Exemple #1
0
        /// <summary>
        /// Gets the unit of a type.
        /// </summary>
        /// <param name="specTypeId">Identifier of the spec.</param>
        /// <returns>The Unit object.</returns>
        public IFCUnit GetIFCProjectUnit(ForgeTypeId specTypeId)
        {
            IFCUnit projectUnit = null;

            if (m_ProjectUnitsDictionary.TryGetValue(specTypeId, out projectUnit))
            {
                return(projectUnit);
            }
            else
            {
                //default units
                if (specTypeId.Equals(SpecTypeId.Length))
                {
                    IFCUnit unit = IFCUnit.ProcessIFCDefaultUnit(specTypeId, UnitSystem.Metric, UnitTypeId.Meters, 1.0 / 0.3048);
                    m_ProjectUnitsDictionary[specTypeId] = unit;
                    return(unit);
                }
                else if (specTypeId.Equals(SpecTypeId.Area))
                {
                    IFCUnit projectLengthUnit = GetIFCProjectUnit(SpecTypeId.Length);

                    UnitSystem  unitSystem = projectLengthUnit.UnitSystem;
                    ForgeTypeId unitName   = unitSystem == UnitSystem.Metric ?
                                             UnitTypeId.SquareMeters : UnitTypeId.SquareFeet;
                    double scaleFactor = unitSystem == UnitSystem.Metric ?
                                         (1.0 / 0.3048) * (1.0 / 0.3048) : 1.0;

                    IFCUnit unit = IFCUnit.ProcessIFCDefaultUnit(specTypeId, unitSystem, unitName, scaleFactor);
                    m_ProjectUnitsDictionary[specTypeId] = unit;
                    return(unit);
                }
                else if (specTypeId.Equals(SpecTypeId.Volume))
                {
                    IFCUnit projectLengthUnit = GetIFCProjectUnit(SpecTypeId.Length);

                    UnitSystem  unitSystem = projectLengthUnit.UnitSystem;
                    ForgeTypeId unitName   = unitSystem == UnitSystem.Metric ?
                                             UnitTypeId.CubicMeters : UnitTypeId.CubicFeet;
                    double scaleFactor = unitSystem == UnitSystem.Metric ?
                                         (1.0 / 0.3048) * (1.0 / 0.3048) * (1.0 / 0.3048) : 1.0;

                    IFCUnit unit = IFCUnit.ProcessIFCDefaultUnit(specTypeId, unitSystem, unitName, scaleFactor);
                    m_ProjectUnitsDictionary[specTypeId] = unit;
                    return(unit);
                }
                else if (specTypeId.Equals(SpecTypeId.Angle))
                {
                    IFCUnit unit = IFCUnit.ProcessIFCDefaultUnit(specTypeId, UnitSystem.Metric, UnitTypeId.Degrees, Math.PI / 180);
                    m_ProjectUnitsDictionary[specTypeId] = unit;
                    return(unit);
                }
                else if (specTypeId.Equals(SpecTypeId.HvacTemperature))
                {
                    IFCUnit unit = IFCUnit.ProcessIFCDefaultUnit(specTypeId, UnitSystem.Metric, UnitTypeId.Kelvin, 1.0);
                    m_ProjectUnitsDictionary[specTypeId] = unit;
                    return(unit);
                }
            }
            return(null);
        }
Exemple #2
0
        private double GetScaleFactorForUnitType(string prefix, ForgeTypeId specTypeId)
        {
            double scaleFactor = m_sPrefixToScaleFactor[prefix];

            const double lengthFactor = (1.0 / 0.3048);
            const double areaFactor   = lengthFactor * lengthFactor;
            const double volumeFactor = areaFactor * lengthFactor;

            // length ^ -2
            if (specTypeId.Equals(SpecTypeId.Illuminance))
            {
                return((scaleFactor * scaleFactor) / areaFactor);
            }
            // length ^ -1
            if (specTypeId.Equals(SpecTypeId.HvacPressure))
            {
                return(scaleFactor / lengthFactor);
            }
            // length
            if (specTypeId.Equals(SpecTypeId.Force) ||
                specTypeId.Equals(SpecTypeId.Length))
            {
                return(scaleFactor * lengthFactor);
            }
            // length ^ 2
            if (specTypeId.Equals(SpecTypeId.Area) ||
                specTypeId.Equals(SpecTypeId.ElectricalPotential) ||
                specTypeId.Equals(SpecTypeId.HvacPower))
            {
                return((scaleFactor * scaleFactor) * areaFactor);
            }
            // length ^ 3
            if (specTypeId.Equals(SpecTypeId.Volume))
            {
                return((scaleFactor * scaleFactor * scaleFactor) * volumeFactor);
            }
            if (specTypeId.Equals(SpecTypeId.Mass))
            {
                return(scaleFactor / 1000.0); // Standard internal scale is kg.
            }
            return(scaleFactor);
        }
Exemple #3
0
        private IDictionary <string, KeyValuePair <ForgeTypeId, ForgeTypeId> > GetSupportedDisplayTypes(ForgeTypeId specTypeId)
        {
            if (m_sSupportedMetricUnitTypes == null)
            {
                m_sSupportedMetricUnitTypes = new Dictionary <ForgeTypeId, IDictionary <string, KeyValuePair <ForgeTypeId, ForgeTypeId> > >();
            }

            IDictionary <string, KeyValuePair <ForgeTypeId, ForgeTypeId> > supportedTypes = null;

            if (!m_sSupportedMetricUnitTypes.TryGetValue(specTypeId, out supportedTypes))
            {
                supportedTypes = new Dictionary <string, KeyValuePair <ForgeTypeId, ForgeTypeId> >();
                if (specTypeId.Equals(SpecTypeId.Area))
                {
                    supportedTypes[""]      = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.SquareMeters, SymbolTypeId.MSup2);
                    supportedTypes["CENTI"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.SquareCentimeters, SymbolTypeId.CmSup2);
                    supportedTypes["MILLI"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.SquareMillimeters, SymbolTypeId.MmSup2);
                }
                else if (specTypeId.Equals(SpecTypeId.Current))
                {
                    supportedTypes[""]      = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Amperes, SymbolTypeId.Ampere);
                    supportedTypes["KILO"]  = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Kiloamperes, SymbolTypeId.KA);
                    supportedTypes["MILLI"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Milliamperes, SymbolTypeId.MA);
                }
                else if (specTypeId.Equals(SpecTypeId.ElectricalFrequency))
                {
                    supportedTypes[""] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Hertz, SymbolTypeId.Hz);
                }
                else if (specTypeId.Equals(SpecTypeId.Illuminance))
                {
                    supportedTypes[""] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Lux, SymbolTypeId.Lx);
                }
                else if (specTypeId.Equals(SpecTypeId.LuminousFlux))
                {
                    supportedTypes[""] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Lumens, SymbolTypeId.Lm);
                }
                else if (specTypeId.Equals(SpecTypeId.LuminousIntensity))
                {
                    supportedTypes[""] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Candelas, SymbolTypeId.Cd);
                }
                else if (specTypeId.Equals(SpecTypeId.ElectricalPotential))
                {
                    supportedTypes[""]      = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Volts, SymbolTypeId.Volt);
                    supportedTypes["KILO"]  = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Kilovolts, SymbolTypeId.KV);
                    supportedTypes["MILLI"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Millivolts, SymbolTypeId.MV);
                }
                else if (specTypeId.Equals(SpecTypeId.Force))
                {
                    supportedTypes[""]     = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Newtons, SymbolTypeId.Newton); // Even if unit is grams, display kg.
                    supportedTypes["KILO"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Kilonewtons, SymbolTypeId.KN);
                }
                else if (specTypeId.Equals(SpecTypeId.HvacPower))
                {
                    supportedTypes[""] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Watts, SymbolTypeId.Watt);
                }
                else if (specTypeId.Equals(SpecTypeId.HvacPressure))
                {
                    supportedTypes[""]     = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Pascals, SymbolTypeId.Pa);
                    supportedTypes["KILO"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Kilopascals, SymbolTypeId.KPa);
                    supportedTypes["MEGA"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Megapascals, SymbolTypeId.MPa);
                }
                else if (specTypeId.Equals(SpecTypeId.Length))
                {
                    supportedTypes[""]      = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Meters, SymbolTypeId.Meter);
                    supportedTypes["CENTI"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Centimeters, SymbolTypeId.Cm);
                    supportedTypes["MILLI"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Millimeters, SymbolTypeId.Mm);
                }
                else if (specTypeId.Equals(SpecTypeId.Mass))
                {
                    supportedTypes[""]     = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Kilograms, SymbolTypeId.Kg); // Even if unit is grams, display kg.
                    supportedTypes["KILO"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Kilograms, SymbolTypeId.Kg);
                }
                else if (specTypeId.Equals(SpecTypeId.MassDensity))
                {
                    supportedTypes[""]     = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.KilogramsPerCubicMeter, SymbolTypeId.KgPerMSup3); // Even if unit is grams, display kg.
                    supportedTypes["KILO"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.KilogramsPerCubicMeter, SymbolTypeId.KgPerMSup3);
                }
                else if (specTypeId.Equals(SpecTypeId.Volume))
                {
                    supportedTypes[""]      = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.CubicMeters, SymbolTypeId.MSup3);
                    supportedTypes["DECI"]  = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.Liters, SymbolTypeId.Liter);
                    supportedTypes["CENTI"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.CubicCentimeters, SymbolTypeId.CmSup3);
                    supportedTypes["MILLI"] = new KeyValuePair <ForgeTypeId, ForgeTypeId>(UnitTypeId.CubicMillimeters, SymbolTypeId.MmSup3);
                }
                m_sSupportedMetricUnitTypes[specTypeId] = supportedTypes;
            }

            return(supportedTypes);
        }