示例#1
0
 public IfcSIUnit(IfcUnitEnum unitType, IfcSIUnitName name)
 {
     Dimensions           = new IfcDimensionalExponents();
     Dimensions.IsDerived = true;
     UnitType             = unitType;
     Name = name;
 }
示例#2
0
        static bool getNamedUnitRepStr(IIfcUnit unitDef, out IfcUnitEnum unitType, out string unitRepStr)
        {
            // Initialize the static Dicts, if it is still empty upon the first use. These Dicts do not need to be reset
            setupUnitRep();

            unitType   = IfcUnitEnum.LENGTHUNIT; // initial value
            unitRepStr = string.Empty;
            if (unitDef is IIfcContextDependentUnit)
            {
                // Not supported yet at this time
            }
            else if (unitDef is IIfcConversionBasedUnit)
            {
                unitType   = ((IIfcConversionBasedUnit)unitDef).UnitType;
                unitRepStr = getConversionBasedUnitRepStr(unitDef);
                if (!string.IsNullOrEmpty(unitRepStr))
                {
                    return(true);
                }
            }
            else if (unitDef is IIfcSIUnit)
            {
                unitType   = ((IIfcSIUnit)unitDef).UnitType;
                unitRepStr = getSIUnitRepStr(unitDef);
                if (!string.IsNullOrEmpty(unitRepStr))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#3
0
 public IfcConversionBasedUnit(IfcDimensionalExponents __Dimensions, IfcUnitEnum __UnitType, IfcLabel __Name, IfcMeasureWithUnit __ConversionFactor)
     : base(__Dimensions, __UnitType)
 {
     this.Name                 = __Name;
     this.ConversionFactor     = __ConversionFactor;
     this.HasExternalReference = new HashSet <IfcExternalReferenceRelationship>();
 }
示例#4
0
 public IfcSIUnit(IfcUnitEnum unitType, IfcSIUnitName name)
 {
     Dimensions = new IfcDimensionalExponents();
     Dimensions.IsDerived = true;
     UnitType = unitType;
     Name = name;
 }
示例#5
0
        public IfcConversionBasedUnit(IfcDimensionalExponents dimensions, IfcUnitEnum unitType, IfcLabel name, IfcMeasureWithUnit conversionFactor) : base(dimensions, unitType)
        {
            HasExternalReference = new List <IfcExternalReferenceRelationship>();

            Name             = name;
            ConversionFactor = conversionFactor;
        }
        public static double GetPower(this IfcUnitAssignment ua, IfcUnitEnum unitType)
        {
           
            IfcSIUnit si = ua.Units.OfType<IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType);
            if (si != null && si.Prefix.HasValue)
                return si.Power();
            else
            {
                IfcConversionBasedUnit cu =
                    ua.Units.OfType<IfcConversionBasedUnit>().FirstOrDefault(u => u.UnitType == unitType);
                if (cu != null)
                {
                    IfcMeasureWithUnit mu = cu.ConversionFactor;
                    IfcSIUnit uc = mu.UnitComponent as IfcSIUnit;
                    //some BIM tools such as StruCAD write the conversion value out as a Length Measure
                    if (uc != null)
                    {
                        ExpressType et = ((ExpressType)mu.ValueComponent);
                        double cFactor = 1.0;
                        if (et.UnderlyingSystemType == typeof(double))
                            cFactor = (double)et.Value;
                        else if (et.UnderlyingSystemType == typeof(int))
                            cFactor = (double)((int)et.Value);
                        else if (et.UnderlyingSystemType == typeof(long))
                            cFactor = (double)((long)et.Value);

                        return uc.Power() * cFactor;
                    }
                }
            }
            return 1.0;
        }
示例#7
0
 protected IfcNamedUnit(DatabaseIfc db, IfcNamedUnit u) : base(db, u)
 {
     if (u.mDimensions > 0)
     {
         Dimensions = db.Factory.Duplicate(u.Dimensions) as IfcDimensionalExponents;
     }
     mUnitType = u.mUnitType;
 }
示例#8
0
 private void Init(string name)
 {
     SiUnitName            = null;
     SiPrefix              = null;
     UnitName              = IfcUnitEnum.USERDEFINED;
     UserDefinedSiUnitName = name; //default if all fails
     ConversionFactor      = 1;
 }
示例#9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 public IfcUnitConverter(string name)
 {
     SiUnitName            = null;
     SiPrefix              = null;
     UnitName              = IfcUnitEnum.USERDEFINED;
     UserDefinedSiUnitName = name; //default if all fails
     ConversionFactor      = 1;
     Convert(name);
 }
示例#10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 public IfcUnitConverter(string name)
 {
     SiUnitName = null;
     SiPrefix = null;
     UnitName = IfcUnitEnum.USERDEFINED;
     UserDefinedSiUnitName = name; //default if all fails
     ConversionFactor = 1;
     Convert(name);
 }
        private static string GetUnit(IIfcUnitAssignment units, IfcUnitEnum type)
        {
            if (units == null)
            {
                return(null);
            }
            var unit = units.Units.OfType <IIfcNamedUnit>().FirstOrDefault(u => u.UnitType == type);

            return(unit != null ? unit.FullName : null);
        }
示例#12
0
        internal static bool IfcCorrectDimensions(IfcUnitEnum unitType, IfcDimensionalExponents dimensions)
        {
            var val = NullableIfcCorrectDimensions(unitType, dimensions);

            if (!val.HasValue)
            {
                throw new ArgumentException("Undetermined value in where clause.");
            }
            return(val.Value);
        }
示例#13
0
        public void SetOrChangeConversionUnit(IfcUnitEnum unitType, ConversionBasedUnit conversionUnit)
        {
            if (UnitsInContext == null)
            {
                UnitsInContext = Model.Instances.New <IfcUnitAssignment>();
            }
            IfcUnitAssignment unitsAssignment = UnitsInContext;

            unitsAssignment.SetOrChangeConversionUnit(unitType, conversionUnit);
        }
        public SIUnit(IfcStore model, IfcSIUnitName name, IfcUnitEnum unitType)
        {
            ifcSiUnit = model.Instances.New <IfcSIUnit>(p =>
            {
                p.Name     = name;
                p.UnitType = unitType;
            });

            this.name     = name;
            this.unitType = unitType;
        }
示例#15
0
        public void SetOrChangeSiUnit(IfcUnitEnum unitType, IfcSIUnitName siUnitName,
                                      IfcSIPrefix?siUnitPrefix)
        {
            if (UnitsInContext == null)
            {
                UnitsInContext = Model.Instances.New <IfcUnitAssignment>();
            }
            IfcUnitAssignment unitsAssignment = UnitsInContext;

            unitsAssignment.SetOrChangeSiUnit(unitType, siUnitName, siUnitPrefix);
        }
示例#16
0
        public static IfcUnitAssignment NewIfc4UnitAssignment(this IModel s, IfcUnitEnum unitType, IfcSIUnitName name, IfcSIPrefix?prefix = null)
        {
            var unitAssignment = s.Instances.New <IfcUnitAssignment>();

            unitAssignment.Units.Add(s.Instances.New <IfcSIUnit>(store =>
            {
                store.UnitType = unitType;
                store.Name     = name;
                store.Prefix   = prefix;
            }));
            return(unitAssignment);
        }
示例#17
0
 internal IfcNamedUnit Find(IfcUnitEnum unit)
 {
     foreach (IfcUnit u in Units)
     {
         IfcNamedUnit nu = u as IfcNamedUnit;
         if (nu != null && nu.UnitType == unit)
         {
             return(nu);
         }
     }
     return(null);
 }
示例#18
0
        public static void SetOrChangeSIUnit(this IfcProject ifcProject, IfcUnitEnum unitType, IfcSIUnitName siUnitName,
                                             IfcSIPrefix?siUnitPrefix)
        {
            IModel model = ifcProject.ModelOf;

            if (ifcProject.UnitsInContext == null)
            {
                ifcProject.UnitsInContext = model.Instances.New <IfcUnitAssignment>();
            }

            IfcUnitAssignment unitsAssignment = ifcProject.UnitsInContext;

            unitsAssignment.SetOrChangeSIUnit(unitType, siUnitName, siUnitPrefix);
        }
示例#19
0
        public static void SetOrChangeConversionUnit(this IfcProject ifcProject, IfcUnitEnum unitType,
                                                     ConversionBasedUnit conversionUnit)
        {
            IModel model = ifcProject.ModelOf;

            if (ifcProject.UnitsInContext == null)
            {
                ifcProject.UnitsInContext = model.Instances.New <IfcUnitAssignment>();
            }

            IfcUnitAssignment unitsAssignment = ifcProject.UnitsInContext;

            unitsAssignment.SetOrChangeConversionUnit(unitType, conversionUnit);
        }
示例#20
0
 public IfcNamedUnit this[IfcUnitEnum unit]
 {
     get
     {
         foreach (IfcUnit u in Units)
         {
             IfcNamedUnit nu = u as IfcNamedUnit;
             if (nu != null && nu.UnitType == unit)
             {
                 return(nu);
             }
         }
         return(null);
     }
 }
示例#21
0
		protected IfcNamedUnit(DatabaseIfc m, IfcUnitEnum unitEnum, bool gendims) : base(m)
		{
			mUnitType = unitEnum;
			if (gendims)
			{
				if (unitEnum == IfcUnitEnum.LENGTHUNIT)
					mDimensions = new IfcDimensionalExponents(m, 1, 0, 0, 0, 0, 0, 0).mIndex;
				else if (unitEnum == IfcUnitEnum.AREAUNIT)
					mDimensions = new IfcDimensionalExponents(m, 2, 0, 0, 0, 0, 0, 0).mIndex;
				else if (unitEnum == IfcUnitEnum.VOLUMEUNIT)
					mDimensions = new IfcDimensionalExponents(m, 3, 0, 0, 0, 0, 0, 0).mIndex;
				else if (unitEnum == IfcUnitEnum.PLANEANGLEUNIT)
					mDimensions = new IfcDimensionalExponents(m, 0, 0, 0, 0, 0, 0, 0).mIndex;
			}
		}
示例#22
0
 private static void SetConversionUnitsParameters(IModel model, IfcConversionBasedUnit unit, IfcLabel name,
                                                  IfcRatioMeasure ratio, IfcUnitEnum unitType, IfcSIUnitName siUnitName,
                                                  IfcSIPrefix?siUnitPrefix, IfcDimensionalExponents dimensions)
 {
     unit.Name             = name;
     unit.ConversionFactor = model.Instances.New <IfcMeasureWithUnit>();
     unit.ConversionFactor.ValueComponent = ratio;
     unit.ConversionFactor.UnitComponent  = model.Instances.New <IfcSIUnit>(s =>
     {
         s.UnitType = unitType;
         s.Name     = siUnitName;
         s.Prefix   = siUnitPrefix;
     });
     unit.Dimensions = dimensions;
 }
示例#23
0
        public static void SetOrChangeConversionUnit(this IfcUnitAssignment ua, IfcUnitEnum unitType, ConversionBasedUnit unit)
        {
            IModel    model = ua.ModelOf;
            IfcSIUnit si    = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType);

            if (si != null)
            {
                ua.Units.Remove(si);
                try
                {
                    model.Delete(si);
                } catch (Exception) {}
            }
            ua.Units.Add(GetNewConversionUnit(model, unitType, unit));
        }
        public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
        {
            switch (propIndex)
            {
            case 0:
                _dimensions = (IfcDimensionalExponents)(value.EntityVal);
                return;

            case 1:
                _unitType = (IfcUnitEnum)System.Enum.Parse(typeof(IfcUnitEnum), value.EnumVal, true);
                return;

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

            case 1:
                _unitType = (IfcUnitEnum)Enum.Parse(typeof(IfcUnitEnum), value.EnumVal, true);
                break;

            default:
                this.HandleUnexpectedAttribute(propIndex, value); break;
            }
        }
示例#26
0
 protected IfcNamedUnit(DatabaseIfc db, IfcUnitEnum unitEnum, bool gendims) : base(db)
 {
     mUnitType = unitEnum;
     if (gendims)
     {
         if (unitEnum == IfcUnitEnum.LENGTHUNIT)
         {
             Dimensions = new IfcDimensionalExponents(db, 1, 0, 0, 0, 0, 0, 0);
         }
         else if (unitEnum == IfcUnitEnum.AREAUNIT)
         {
             Dimensions = new IfcDimensionalExponents(db, 2, 0, 0, 0, 0, 0, 0);
         }
         else if (unitEnum == IfcUnitEnum.VOLUMEUNIT)
         {
             Dimensions = new IfcDimensionalExponents(db, 3, 0, 0, 0, 0, 0, 0);
         }
         else if (unitEnum == IfcUnitEnum.MASSUNIT)
         {
             Dimensions = new IfcDimensionalExponents(db, 0, 1, 0, 0, 0, 0, 0);
         }
         else if (unitEnum == IfcUnitEnum.TIMEUNIT)
         {
             Dimensions = new IfcDimensionalExponents(db, 0, 0, 1, 0, 0, 0, 0);
         }
         else if (unitEnum == IfcUnitEnum.ELECTRICCURRENTUNIT)
         {
             Dimensions = new IfcDimensionalExponents(db, 0, 0, 0, 1, 0, 0, 0);
         }
         else if (unitEnum == IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT)
         {
             Dimensions = new IfcDimensionalExponents(db, 0, 0, 0, 0, 1, 0, 0);
         }
         else if (unitEnum == IfcUnitEnum.AMOUNTOFSUBSTANCEUNIT)
         {
             Dimensions = new IfcDimensionalExponents(db, 0, 0, 0, 0, 0, 1, 0);
         }
         else if (unitEnum == IfcUnitEnum.LUMINOUSINTENSITYUNIT)
         {
             Dimensions = new IfcDimensionalExponents(db, 0, 0, 0, 0, 0, 0, 1);
         }
         else if (unitEnum == IfcUnitEnum.PLANEANGLEUNIT)
         {
             Dimensions = new IfcDimensionalExponents(db, 0, 0, 0, 0, 0, 0, 0);
         }
     }
 }
示例#27
0
        /// <summary>
        /// Convert string back into IfcSIUnitName and IfcSIPrefix enumerations
        /// </summary>
        /// <param name="unitType">IfcUnitEnum unit type</param>
        /// <param name="value">string representing the unit type</param>
        private void SetUnitToProject(IfcUnitEnum unitType, string value)
        {
            IfcSIUnitName?returnUnit;
            IfcSIPrefix?  returnPrefix;

            IfcUnitAssignment ifcUnitAssignment = GetProjectUnitAssignment();

            if (GetUnitEnumerations(value, out returnUnit, out returnPrefix))
            {
                if (returnUnit != null)
                {
                    ifcUnitAssignment.SetOrChangeSiUnit(unitType, (IfcSIUnitName)returnUnit.Value, returnPrefix);
                }
            }
            else
            {
                ConversionBasedUnit conversionBasedUnit;
                value = value.Trim().Replace(" ", "_").ToUpper();
                //see if the passed value contains a ConversionBasedUnit value, i.e INCHS would match ConversionBasedUnit.INCH
                string[] cBasedUnits = Enum.GetNames(typeof(ConversionBasedUnit));
                if (!cBasedUnits.Contains(value))
                {
                    foreach (string str in cBasedUnits)
                    {
                        if (str == value)
                        {
                            break;
                        }
                        string test = str.Split('_').First();
                        //try both ways
                        if ((value.Contains(test)) ||
                            (test.Contains(value))
                            )
                        {
                            value = str;
                            break;
                        }
                    }
                }

                if (Enum.TryParse(value, out conversionBasedUnit))
                {
                    ifcUnitAssignment.SetOrChangeConversionUnit(unitType, conversionBasedUnit);
                }
            }
        }
        public void SetOrChangeConversionUnit(IfcUnitEnum unitType, ConversionBasedUnit unit)
        {
            var si = Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType);

            if (si != null)
            {
                Units.Remove(si);
                try
                {
                    Model.Delete(si);
                }
                catch (Exception)
                {
                    // ignored
                }
            }
            Units.Add(GetNewConversionUnit(Model, unitType, unit));
        }
示例#29
0
        internal double ScaleSI(IfcUnitEnum unitType)
        {
            IfcNamedUnit namedUnit = this[unitType];

            if (namedUnit != null)
            {
                IfcSIUnit siUnit = namedUnit as IfcSIUnit;
                if (siUnit != null)
                {
                    return(siUnit.SIFactor);
                }
                IfcConversionBasedUnit conversionBasedUnit = namedUnit as IfcConversionBasedUnit;
                if (conversionBasedUnit != null)
                {
                    return(conversionBasedUnit.SIFactor);
                }
            }
            return(1);
        }
        public double Power(IfcUnitEnum unitType)
        {
            var si = Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType);

            if (si != null && si.Prefix.HasValue)
            {
                return(si.Power);
            }
            var cu =
                Units.OfType <IfcConversionBasedUnit>().FirstOrDefault(u => u.UnitType == unitType);

            if (cu == null)
            {
                return(1.0);
            }
            var mu = cu.ConversionFactor;
            var uc = mu.UnitComponent as IfcSIUnit;

            //some BIM tools such as StruCAD write the conversion value out as a Length Measure
            if (uc == null)
            {
                return(1.0);
            }


            var et      = ((IExpressValueType)mu.ValueComponent);
            var cFactor = 1.0;

            if (et.UnderlyingSystemType == typeof(double))
            {
                cFactor = (double)et.Value;
            }
            else if (et.UnderlyingSystemType == typeof(int))
            {
                cFactor = (int)et.Value;
            }
            else if (et.UnderlyingSystemType == typeof(long))
            {
                cFactor = (long)et.Value;
            }

            return(uc.Power * cFactor);
        }
示例#31
0
 internal double ScaleSI(IfcUnitEnum unitType)
 {
     foreach (IfcNamedUnit namedUnit in Units.OfType <IfcNamedUnit>())
     {
         if (namedUnit.UnitType == unitType)
         {
             IfcSIUnit siUnit = namedUnit as IfcSIUnit;
             if (siUnit != null)
             {
                 return(siUnit.SIFactor);
             }
             IfcConversionBasedUnit conversionBasedUnit = namedUnit as IfcConversionBasedUnit;
             if (conversionBasedUnit != null)
             {
                 return(conversionBasedUnit.SIFactor);
             }
         }
     }
     return(1);
 }
示例#32
0
        public static IIfcSIUnit NewIfcSIUnit(this IModel s, IfcUnitEnum unitType, IfcSIUnitName name, IfcSIPrefix?prefix = null)
        {
            switch (s.SchemaVersion)
            {
            case Xbim.Common.Step21.XbimSchemaVersion.Ifc2X3:
                return(s.NewIfc2x3SIUnit(unitType, name, prefix));

            case Xbim.Common.Step21.XbimSchemaVersion.Ifc4:
            case Xbim.Common.Step21.XbimSchemaVersion.Ifc4x1:
                return(s.Instances.New <Xbim.Ifc4.MeasureResource.IfcSIUnit>(x =>
                {
                    x.Name = name;
                    x.Prefix = prefix;
                    x.UnitType = unitType;
                }));

            default:
                throw new NotImplementedException($"Missing implementation for {s.SchemaVersion}");
            }
        }
示例#33
0
 internal double getScaleSI(IfcUnitEnum unitType)
 {
     foreach (IfcUnit u in Units)
     {
         IfcNamedUnit nu = u as IfcNamedUnit;
         if (nu != null && nu.UnitType == unitType)
         {
             IfcSIUnit si = nu as IfcSIUnit;
             if (si != null)
             {
                 return(si.getSIFactor());
             }
             IfcConversionBasedUnit cbu = nu as IfcConversionBasedUnit;
             if (cbu != null)
             {
                 return(cbu.getSIFactor());
             }
         }
     }
     return(1);
 }
示例#34
0
        public static void SetOrChangeSIUnit(this IfcUnitAssignment ua, IfcUnitEnum unitType, IfcSIUnitName siUnitName,
                                             IfcSIPrefix?siUnitPrefix)
        {
            IModel    model = ua.ModelOf;
            IfcSIUnit si    = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType);

            if (si != null)
            {
                si.Prefix = siUnitPrefix;
                si.Name   = siUnitName;
            }
            else
            {
                ua.Units.Add(model.Instances.New <IfcSIUnit>(s =>
                {
                    s.UnitType = unitType;
                    s.Name     = siUnitName;
                    s.Prefix   = siUnitPrefix;
                }));
            }
        }
示例#35
0
        /// <summary>
        /// Converts a string
        /// </summary>
        /// <param name="name"></param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public void Convert(string name)
        {
            Init(name);
            if (string.IsNullOrWhiteSpace(name)) return;
            var trimmedName = name.ToLowerInvariant();
            trimmedName = Regex.Replace(trimmedName, "[^a-z0-9]+", string.Empty, RegexOptions.Compiled);
            //trimmedName = Regex.Replace(trimmedName, @"\s+", "");
            //check for a metric SI value
            switch (trimmedName)
            {
                case "millimeter":
                case "millimeters":
                case "millimetre":
                case "millimetres":
                case "mm":
                    SiUnitName = IfcSIUnitName.METRE;
                    SiPrefix = IfcSIPrefix.MILLI;
                    break;
                case "centimeter":
                case "centimeters":
                case "centimetre":
                case "centimetres":
                case "cm":
                    SiUnitName = IfcSIUnitName.METRE;
                    SiPrefix = IfcSIPrefix.CENTI;
                    break;
                case "meter":
                case "meters":
                case "metre":
                case "metres":
                case "m":
                    SiUnitName = IfcSIUnitName.METRE;
                    SiPrefix = null;
                    break;
                case "kilometer":
                case "kilometers":
                case "kilometre":
                case "kilometres":
                case "km":
                    SiUnitName = IfcSIUnitName.METRE;
                    SiPrefix = IfcSIPrefix.KILO;
                    break;
                case "squaremillimeter":
                case "squaremillimeters":
                case "squaremillimetre":
                case "squaremillimetres":
                case "mm2":
                    SiUnitName = IfcSIUnitName.SQUARE_METRE;
                    SiPrefix = IfcSIPrefix.MILLI;
                    break;
                case "squarecentimeter":
                case "squarecentimeters":
                case "squarecentimetre":
                case "squarecentimetres":
                case "cm2":
                    SiUnitName = IfcSIUnitName.SQUARE_METRE;
                    SiPrefix = IfcSIPrefix.CENTI;
                    break;
                case "squaremeter":
                case "squaremeters":
                case "squaremetre":
                case "squaremetres":
                case "m2":
                    SiUnitName = IfcSIUnitName.SQUARE_METRE;
                    SiPrefix = null;
                    break;
                case "squarekilometer":
                case "squarekilometers":
                case "squarekilometre":
                case "squarekilometres":
                    SiUnitName = IfcSIUnitName.SQUARE_METRE;
                    SiPrefix = IfcSIPrefix.KILO;
                    break;
                case "cubicmillimeter":
                case "cubicmillimeters":
                case "cubicmillimetre":
                case "cubicmillimetres":
                case "mm3":
                    SiUnitName = IfcSIUnitName.CUBIC_METRE;
                    SiPrefix = IfcSIPrefix.MILLI;
                    break;
                case "cubiccentimeter":
                case "cubiccentimeters":
                case "cubiccentimetre":
                case "cubiccentimetres":
                case "cm3":
                    SiUnitName = IfcSIUnitName.CUBIC_METRE;
                    SiPrefix = IfcSIPrefix.CENTI;
                    break;
                case "cubicmeter":
                case "cubicmeters":
                case "cubicmetre":
                case "cubicmetres":
                case "m3":
                    SiUnitName = IfcSIUnitName.CUBIC_METRE;
                    SiPrefix = null;
                    break;
                case "cubickilometer":
                case "cubickilometers":
                case "cubickilometre":
                case "cubickilometres":
                case "km3":
                    SiUnitName = IfcSIUnitName.CUBIC_METRE;
                    SiPrefix = IfcSIPrefix.KILO;
                    break;
            }

            if (!SiUnitName.HasValue) //see if it is imperial
            {
                switch (trimmedName)
                {
                    case "inches":
                    case "inch":
                    case "\"":
                        SiUnitName = IfcSIUnitName.METRE;
                        ConversionFactor = 0.0254;
                        break;
                    case "feet":
                    case "foot":
                    case "ft":
                    case "'":
                        SiUnitName = IfcSIUnitName.METRE;
                        ConversionFactor = 0.3048;
                        break;
                    case "yards":
                    case "yard":
                    case "yds":
                    case "yd":
                        SiUnitName = IfcSIUnitName.METRE;
                        ConversionFactor = 0.9144;
                        break;
                    case "miles":
                    case "mile":
                        SiUnitName = IfcSIUnitName.METRE;
                        ConversionFactor = 1609.344;
                        break;
                    case "squareinches":
                    case "squareinch":
                        SiUnitName = IfcSIUnitName.SQUARE_METRE;
                        ConversionFactor = 0.00064516;
                        break;
                    case "squarefeet":
                    case "squarefoot":
                    case "sqft":
                    case "ft2":
                        SiUnitName = IfcSIUnitName.SQUARE_METRE;
                        ConversionFactor = 0.09290304;
                        break;
                    case "squareyards":
                    case "squareyard":
                    case "sqyd":
                    case "yd2":
                    case "yard2":
                        SiUnitName = IfcSIUnitName.SQUARE_METRE;
                        ConversionFactor = 0.83612736;
                        break;
                    case "squaremiles":
                    case "squaremile":
                        SiUnitName = IfcSIUnitName.SQUARE_METRE;
                        ConversionFactor = 2589988.11;
                        break;
                    case "cubicinches":
                    case "cubicinch":
                        SiUnitName = IfcSIUnitName.CUBIC_METRE;
                        ConversionFactor = 1.6387064e-5;
                        break;
                    case "cubicfeet":
                    case "cubicfoot":
                    case "foot3":
                    case "ft3":
                        SiUnitName = IfcSIUnitName.CUBIC_METRE;
                        ConversionFactor = 0.0283168466;
                        break;
                    case "cubicyards":
                    case "cubicyard":
                    case "yard3":
                    case "yd3":
                        SiUnitName = IfcSIUnitName.CUBIC_METRE;
                        ConversionFactor = 0.764554858;
                        break;
                    case "cubicmiles":
                    case "cubicmile":
                        SiUnitName = IfcSIUnitName.CUBIC_METRE;
                        ConversionFactor = 4.16818183e9;
                        break;
                }
            }

            if (SiUnitName.HasValue)
            {
                switch (SiUnitName)
                {
                    case IfcSIUnitName.AMPERE:
                        break;
                    case IfcSIUnitName.BECQUEREL:
                        break;
                    case IfcSIUnitName.CANDELA:
                        break;
                    case IfcSIUnitName.COULOMB:
                        break;
                    case IfcSIUnitName.CUBIC_METRE:
                        UnitName = IfcUnitEnum.VOLUMEUNIT;
                        break;
                    case IfcSIUnitName.DEGREE_CELSIUS:
                        break;
                    case IfcSIUnitName.FARAD:
                        break;
                    case IfcSIUnitName.GRAM:
                        break;
                    case IfcSIUnitName.GRAY:
                        break;
                    case IfcSIUnitName.HENRY:
                        break;
                    case IfcSIUnitName.HERTZ:
                        break;
                    case IfcSIUnitName.JOULE:
                        break;
                    case IfcSIUnitName.KELVIN:
                        break;
                    case IfcSIUnitName.LUMEN:
                        break;
                    case IfcSIUnitName.LUX:
                        break;
                    case IfcSIUnitName.METRE:
                        UnitName = IfcUnitEnum.LENGTHUNIT;
                        break;
                    case IfcSIUnitName.MOLE:
                        break;
                    case IfcSIUnitName.NEWTON:
                        break;
                    case IfcSIUnitName.OHM:
                        break;
                    case IfcSIUnitName.PASCAL:
                        break;
                    case IfcSIUnitName.RADIAN:
                        break;
                    case IfcSIUnitName.SECOND:
                        break;
                    case IfcSIUnitName.SIEMENS:
                        break;
                    case IfcSIUnitName.SIEVERT:
                        break;
                    case IfcSIUnitName.SQUARE_METRE:
                        UnitName = IfcUnitEnum.AREAUNIT;
                        break;
                    case IfcSIUnitName.STERADIAN:
                        break;
                    case IfcSIUnitName.TESLA:
                        break;
                    case IfcSIUnitName.VOLT:
                        break;
                    case IfcSIUnitName.WATT:
                        break;
                    case IfcSIUnitName.WEBER:
                        break;
                    case null:
                        break;
                    default:
                        throw new ArgumentOutOfRangeException("name");
                }
            }
        }
示例#36
0
 private void Init(string name)
 {
     SiUnitName = null;
     SiPrefix = null;
     UnitName = IfcUnitEnum.USERDEFINED;
     UserDefinedSiUnitName = name; //default if all fails
     ConversionFactor = 1;
 }
示例#37
0
 /// <summary>
 /// Sets SI unit or change it if it exists. It does not affect any physical 
 /// values in the model, it just changes their meaning.
 /// </summary>
 /// <param name="UnitType">Enumeration of unit types</param>
 /// <param name="siUnitName">Enumeration of base SI unit names</param>
 /// <param name="siUnitPrefix">Enumeration of SI units prefixes</param>
 public void SetOrChangeSIUnit(IfcUnitEnum UnitType, IfcSIUnitName siUnitName, IfcSIPrefix? siUnitPrefix)
 {
     ((IfcProject)Model.IfcProject).SetOrChangeSIUnit(UnitType, siUnitName, siUnitPrefix);
 }
示例#38
0
        /// <summary>
        /// Convert string back into IfcSIUnitName and IfcSIPrefix enumerations
        /// </summary>
        /// <param name="unitType">IfcUnitEnum unit type</param>
        /// <param name="value">string representing the unit type</param>
        private void SetUnitToProject(IfcUnitEnum unitType, string value)
        {
            IfcSIUnitName? returnUnit;
            IfcSIPrefix? returnPrefix;

            IfcUnitAssignment ifcUnitAssignment = GetProjectUnitAssignment();
            if (GetUnitEnumerations(value, out returnUnit, out returnPrefix))
            {
                ifcUnitAssignment.SetOrChangeSIUnit(unitType, (IfcSIUnitName)returnUnit, returnPrefix);
            }
            else
            {
                ConversionBasedUnit conversionBasedUnit;
                value = value.Trim().Replace(" ", "_").ToUpper();
                //see if the passed value contains a ConversionBasedUnit value, i.e INCHS would match ConversionBasedUnit.INCH
                string[] cBasedUnits = Enum.GetNames(typeof(ConversionBasedUnit));
                if (!cBasedUnits.Contains(value))
                {
                    foreach (string str in cBasedUnits)
                    {
                        if (str == value)
                        {
                            break;
                        }
                        string test = str.Split('_').First();
                        //try both ways
                        if ((value.Contains(test)) ||
                            (test.Contains(value))
                            )
                        {
                            value = str;
                            break;
                        }

                    }
                }
                
                if (Enum.TryParse(value, out conversionBasedUnit))
                {
                    ifcUnitAssignment.SetOrChangeConversionUnit(unitType, conversionBasedUnit);
                }
            }
        }
示例#39
0
		protected IfcNamedUnit(IfcNamedUnit p) : base() { mDimensions = p.mDimensions; mUnitType = p.mUnitType; }
        public static void SetOrChangeSIUnit(this IfcProject ifcProject, IfcUnitEnum unitType, IfcSIUnitName siUnitName,
                                             IfcSIPrefix? siUnitPrefix)
        {
            IModel model = ifcProject.ModelOf;
            if (ifcProject.UnitsInContext == null)
            {
                ifcProject.UnitsInContext = model.Instances.New<IfcUnitAssignment>();
            }

            IfcUnitAssignment unitsAssignment = ifcProject.UnitsInContext;
            unitsAssignment.SetOrChangeSIUnit(unitType, siUnitName, siUnitPrefix);
        }
示例#41
0
		internal IfcConversionBasedUnitWithOffset(IfcUnitEnum unit, string name, IfcMeasureWithUnit mu, double offset)
			: base(unit, name, mu) { mConversionOffset = offset; }
示例#42
0
		internal IfcConversionBasedUnit(IfcUnitEnum unit, string name, IfcMeasureWithUnit mu)
			: base(mu.mDatabase, unit, true) { Name = name.Replace("'", ""); mConversionFactor = mu.mIndex; }
        private static IfcConversionBasedUnit GetNewConversionUnit(IModel model, IfcUnitEnum unitType, ConversionBasedUnit unitEnum)
        {
            IfcConversionBasedUnit unit = model.Instances.New<IfcConversionBasedUnit>();
            unit.UnitType = unitType;

            switch (unitEnum)
            {
                case ConversionBasedUnit.INCH:
                    SetConversionUnitsParameters(model, unit, "inch", 25.4, IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE,
                                                 IfcSIPrefix.MILLI, GetLengthDimension(model));
                    break;
                case ConversionBasedUnit.FOOT:
                    SetConversionUnitsParameters(model, unit, "foot", 304.8, IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE,
                                                 IfcSIPrefix.MILLI, GetLengthDimension(model));
                    break;
                case ConversionBasedUnit.YARD:
                    SetConversionUnitsParameters(model, unit, "yard", 914, IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE,
                                                 IfcSIPrefix.MILLI, GetLengthDimension(model));
                    break;
                case ConversionBasedUnit.MILE:
                    SetConversionUnitsParameters(model, unit, "mile", 1609, IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE,
                                                 null, GetLengthDimension(model));
                    break;
                case ConversionBasedUnit.ACRE:
                    SetConversionUnitsParameters(model, unit, "acre", 4046.86, IfcUnitEnum.AREAUNIT,
                                                 IfcSIUnitName.SQUARE_METRE, null, GetAreaDimension(model));
                    break;
                case ConversionBasedUnit.LITRE:
                    SetConversionUnitsParameters(model, unit, "litre", 0.001, IfcUnitEnum.VOLUMEUNIT,
                                                 IfcSIUnitName.CUBIC_METRE, null, GetVolumeDimension(model));
                    break;
                case ConversionBasedUnit.PINT_UK:
                    SetConversionUnitsParameters(model, unit, "pint UK", 0.000568, IfcUnitEnum.VOLUMEUNIT,
                                                 IfcSIUnitName.CUBIC_METRE, null, GetVolumeDimension(model));
                    break;
                case ConversionBasedUnit.PINT_US:
                    SetConversionUnitsParameters(model, unit, "pint US", 0.000473, IfcUnitEnum.VOLUMEUNIT,
                                                 IfcSIUnitName.CUBIC_METRE, null, GetVolumeDimension(model));
                    break;
                case ConversionBasedUnit.GALLON_UK:
                    SetConversionUnitsParameters(model, unit, "gallon UK", 0.004546, IfcUnitEnum.VOLUMEUNIT,
                                                 IfcSIUnitName.CUBIC_METRE, null, GetVolumeDimension(model));
                    break;
                case ConversionBasedUnit.GALLON_US:
                    SetConversionUnitsParameters(model, unit, "gallon US", 0.003785, IfcUnitEnum.VOLUMEUNIT,
                                                 IfcSIUnitName.CUBIC_METRE, null, GetVolumeDimension(model));
                    break;
                case ConversionBasedUnit.OUNCE:
                    SetConversionUnitsParameters(model, unit, "ounce", 28.35, IfcUnitEnum.MASSUNIT, IfcSIUnitName.GRAM,
                                                 null, GetMassDimension(model));
                    break;
                case ConversionBasedUnit.POUND:
                    SetConversionUnitsParameters(model, unit, "pound", 0.454, IfcUnitEnum.MASSUNIT, IfcSIUnitName.GRAM,
                                                 IfcSIPrefix.KILO, GetMassDimension(model));
                    break;
                case ConversionBasedUnit.SQUARE_FOOT:
                    SetConversionUnitsParameters(model, unit, "square foot", 92903.04 , IfcUnitEnum.AREAUNIT, IfcSIUnitName.METRE,
                                                 IfcSIPrefix.MILLI, GetAreaDimension(model));
                    break;
                case ConversionBasedUnit.CUBIC_FOOT:
                    SetConversionUnitsParameters(model, unit, "cubic foot", 28316846.6, IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.METRE,
                                                 IfcSIPrefix.MILLI,  GetVolumeDimension(model));
                    break;
            }

            return unit;
        }
 private static void SetConversionUnitsParameters(IModel model, IfcConversionBasedUnit unit, IfcLabel name,
                                                  IfcRatioMeasure ratio, IfcUnitEnum unitType, IfcSIUnitName siUnitName,
                                                  IfcSIPrefix? siUnitPrefix, IfcDimensionalExponents dimensions)
 {
     unit.Name = name;
     unit.ConversionFactor = model.Instances.New<IfcMeasureWithUnit>();
     unit.ConversionFactor.ValueComponent = ratio;
     unit.ConversionFactor.UnitComponent = model.Instances.New<IfcSIUnit>(s =>
                                                                    {
                                                                        s.UnitType = unitType;
                                                                        s.Name = siUnitName;
                                                                        s.Prefix = siUnitPrefix;
                                                                    });
     unit.Dimensions = dimensions;
 }
 public static void SetOrChangeConversionUnit(this IfcUnitAssignment ua, IfcUnitEnum unitType, ConversionBasedUnit unit)
 {
     IModel model = ua.ModelOf;
     IfcSIUnit si = ua.Units.OfType<IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType);
     if (si != null)
     {
         ua.Units.Remove(si);
         try
         {
             model.Delete(si);
         } catch (Exception){}
     }
     ua.Units.Add(GetNewConversionUnit(model, unitType, unit));
 }
 public static void SetOrChangeSIUnit(this IfcUnitAssignment ua, IfcUnitEnum unitType, IfcSIUnitName siUnitName,
                                      IfcSIPrefix? siUnitPrefix)
 {
     IModel model = ua.ModelOf;
     IfcSIUnit si = ua.Units.OfType<IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType);
     if (si != null)
     {
         si.Prefix = siUnitPrefix;
         si.Name = siUnitName;
     }
     else
     {
         ua.Units.Add(model.Instances.New<IfcSIUnit>(s =>
                                                          {
                                                              s.UnitType = unitType;
                                                              s.Name = siUnitName;
                                                              s.Prefix = siUnitPrefix;
                                                          }));
     }
 }
示例#47
0
 public virtual void IfcParse(int propIndex, IPropertyValue value)
 {
     switch (propIndex)
     {
         case 0:
             _dimensions = (IfcDimensionalExponents) value.EntityVal;
             break;
         case 1:
             _unitType = (IfcUnitEnum) Enum.Parse(typeof (IfcUnitEnum), value.EnumVal, true);
             break;
         default:
             this.HandleUnexpectedAttribute(propIndex, value); break;
     }
 }
 public static IfcDimensionalExponents DimensionsForUnit(IfcUnitEnum unit, IfcDimensionalExponents Dim)
 {
     switch (unit)
     {
         case IfcUnitEnum.LENGTHUNIT:
             return new IfcDimensionalExponents(1, 0, 0, 0, 0, 0, 0);
         case IfcUnitEnum.MASSUNIT:
             return new IfcDimensionalExponents(0, 1, 0, 0, 0, 0, 0);
         case IfcUnitEnum.TIMEUNIT:
             return new IfcDimensionalExponents(0, 0, 1, 0, 0, 0, 0);
         case IfcUnitEnum.ELECTRICCURRENTUNIT:
             return new IfcDimensionalExponents(0, 0, 0, 1, 0, 0, 0);
         case IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT:
             return new IfcDimensionalExponents(0, 0, 0, 0, 1, 0, 0);
         case IfcUnitEnum.AMOUNTOFSUBSTANCEUNIT:
             return new IfcDimensionalExponents(0, 0, 0, 0, 0, 1, 0);
         case IfcUnitEnum.LUMINOUSINTENSITYUNIT:
             return new IfcDimensionalExponents(0, 0, 0, 0, 0, 0, 1);
         case IfcUnitEnum.PLANEANGLEUNIT:
             return new IfcDimensionalExponents(0, 0, 0, 0, 0, 0, 0);
         case IfcUnitEnum.SOLIDANGLEUNIT:
             return new IfcDimensionalExponents(0, 0, 0, 0, 0, 0, 0);
         case IfcUnitEnum.AREAUNIT:
             return new IfcDimensionalExponents(2, 0, 0, 0, 0, 0, 0);
         case IfcUnitEnum.VOLUMEUNIT:
             return new IfcDimensionalExponents(3, 0, 0, 0, 0, 0, 0);
         case IfcUnitEnum.ABSORBEDDOSEUNIT:
             return new IfcDimensionalExponents(2, 0, -2, 0, 0, 0, 0);
         case IfcUnitEnum.RADIOACTIVITYUNIT:
             return new IfcDimensionalExponents(0, 0, -1, 0, 0, 0, 0);
         case IfcUnitEnum.ELECTRICCAPACITANCEUNIT:
             return new IfcDimensionalExponents(-2, 1, 4, 1, 0, 0, 0);
         case IfcUnitEnum.DOSEEQUIVALENTUNIT:
             return new IfcDimensionalExponents(2, 0, -2, 0, 0, 0, 0);
         case IfcUnitEnum.ELECTRICCHARGEUNIT:
             return new IfcDimensionalExponents(0, 0, 1, 1, 0, 0, 0);
         case IfcUnitEnum.ELECTRICCONDUCTANCEUNIT:
             return new IfcDimensionalExponents(-2, -1, 3, 2, 0, 0, 0);
         case IfcUnitEnum.ELECTRICVOLTAGEUNIT:
             return new IfcDimensionalExponents(2, 1, -3, -1, 0, 0, 0);
         case IfcUnitEnum.ELECTRICRESISTANCEUNIT:
             return new IfcDimensionalExponents(2, 1, -3, -2, 0, 0, 0);
         case IfcUnitEnum.ENERGYUNIT:
             return new IfcDimensionalExponents(2, 1, -2, 0, 0, 0, 0);
         case IfcUnitEnum.FORCEUNIT:
             return new IfcDimensionalExponents(1, 1, -2, 0, 0, 0, 0);
         case IfcUnitEnum.FREQUENCYUNIT:
             return new IfcDimensionalExponents(0, 0, -1, 0, 0, 0, 0);
         case IfcUnitEnum.INDUCTANCEUNIT:
             return new IfcDimensionalExponents(2, 1, -2, -2, 0, 0, 0);
         case IfcUnitEnum.ILLUMINANCEUNIT:
             return new IfcDimensionalExponents(-2, 0, 0, 0, 0, 0, 1);
         case IfcUnitEnum.LUMINOUSFLUXUNIT:
             return new IfcDimensionalExponents(0, 0, 0, 0, 0, 0, 1);
         case IfcUnitEnum.MAGNETICFLUXUNIT:
             return new IfcDimensionalExponents(2, 1, -2, -1, 0, 0, 0);
         case IfcUnitEnum.MAGNETICFLUXDENSITYUNIT:
             return new IfcDimensionalExponents(0, 1, -2, -1, 0, 0, 0);
         case IfcUnitEnum.POWERUNIT:
             return new IfcDimensionalExponents(2, 1, -3, 0, 0, 0, 0);
         case IfcUnitEnum.PRESSUREUNIT:
             return new IfcDimensionalExponents(-1, 1, -2, 0, 0, 0, 0);
         default:
             return new IfcDimensionalExponents(0, 0, 0, 0, 0, 0, 0);
     }
 }
示例#49
0
        internal double getScaleSI(IfcUnitEnum unitType)
        {
            List<IfcUnit> units = Units;
            foreach (IfcUnit u in units)
            {
                IfcNamedUnit nu = u as IfcNamedUnit;
                if (nu != null && nu.UnitType == unitType)
                {
                    IfcSIUnit si = nu as IfcSIUnit;
                    if (si != null)
                        return si.getSIFactor();
                    IfcConversionBasedUnit cbu = nu as IfcConversionBasedUnit;
                    if (cbu != null)
                    {
                        return cbu.getSIFactor();

                    }
                }

            }
            return 1;
        }
示例#50
0
 protected IfcNamedUnit(DatabaseIfc db, IfcNamedUnit u)
     : base(db,u)
 {
     if(u.mDimensions > 0) Dimensions = db.Factory.Duplicate(u.Dimensions) as IfcDimensionalExponents; mUnitType = u.mUnitType;
 }
示例#51
0
 internal IfcNamedUnit Find(IfcUnitEnum unit)
 {
     List<IfcUnit> units = Units;
     foreach (IfcUnit u in units)
     {
         IfcNamedUnit nu = u as IfcNamedUnit;
         if (nu != null && nu.UnitType == unit)
             return nu;
     }
     return null;
 }
示例#52
0
		public IfcSIUnit(DatabaseIfc m, IfcUnitEnum unitEnum, IfcSIPrefix pref, IfcSIUnitName name) : base(m, unitEnum, false) { mPrefix = pref; mName = name; }
        public static void SetOrChangeConversionUnit(this IfcProject ifcProject, IfcUnitEnum unitType,
                                                     ConversionBasedUnit conversionUnit)
        {
            IModel model = ifcProject.ModelOf;
            if (ifcProject.UnitsInContext == null)
            {
                ifcProject.UnitsInContext = model.Instances.New<IfcUnitAssignment>();
            }

            IfcUnitAssignment unitsAssignment = ifcProject.UnitsInContext;
            unitsAssignment.SetOrChangeConversionUnit(unitType, conversionUnit);
        }