using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.DB; namespace KDCS.Utils { // // 요약: // The units and display format used to format numbers as strings. Also used for // unit conversions. // // 설명: // Display units are used for two purposes: // 1. Formatting and parsing string representations of values. See FormatOptions.DisplayUnit // and the formatting and parsing utilities in the UnitFormatUtils class. // 2. Conversion of values from one unit to another. See the unit conversion utilities // in the UnitUtils class. // Most display units represent simple units like meters, square feet, or degrees, // and are formatted as decimal numbers. Some display units represent specialized // formatting methods like "feet and fractional inches" or "degrees, minutes and // seconds". Such display units still correspond to an underlying simple unit when // used with the conversion utilities. public enum DisplayUnitType { DUT_UNDEFINED = -2, DUT_CUSTOM = -1, DUT_METERS = 0, DUT_CENTIMETERS = 1, DUT_MILLIMETERS = 2, DUT_DECIMAL_FEET = 3, DUT_FEET_FRACTIONAL_INCHES = 4, DUT_FRACTIONAL_INCHES = 5, DUT_DECIMAL_INCHES = 6, DUT_ACRES = 7, DUT_HECTARES = 8, DUT_METERS_CENTIMETERS = 9, DUT_CUBIC_YARDS = 10, DUT_SQUARE_FEET = 11, DUT_SQUARE_METERS = 12, DUT_CUBIC_FEET = 13, DUT_CUBIC_METERS = 14, DUT_DECIMAL_DEGREES = 15, DUT_DEGREES_AND_MINUTES = 16, DUT_GENERAL = 17, DUT_FIXED = 18, DUT_PERCENTAGE = 19, DUT_SQUARE_INCHES = 20, DUT_SQUARE_CENTIMETERS = 21, DUT_SQUARE_MILLIMETERS = 22, DUT_CUBIC_INCHES = 23, DUT_CUBIC_CENTIMETERS = 24, DUT_CUBIC_MILLIMETERS = 25, // // 요약: // liter (L) DUT_LITERS = 26, // // 요약: // gallon (U.S.) (gal) DUT_GALLONS_US = 27, // // 요약: // kilogram per cubic meter (kg/m³) DUT_KILOGRAMS_PER_CUBIC_METER = 28, // // 요약: // pound per cubic foot (lb/ft³) DUT_POUNDS_MASS_PER_CUBIC_FOOT = 29, // // 요약: // pound per cubic inch (lb/in³) DUT_POUNDS_MASS_PER_CUBIC_INCH = 30, // // 요약: // British thermal unit[IT] (Btu[IT]) DUT_BRITISH_THERMAL_UNITS = 31, // // 요약: // calorie[IT] (cal[IT]) DUT_CALORIES = 32, // // 요약: // kilocalorie[IT] (kcal[IT]) DUT_KILOCALORIES = 33, // // 요약: // joule (J) DUT_JOULES = 34, // // 요약: // kilowatt hour (kW · h) DUT_KILOWATT_HOURS = 35, // // 요약: // therm (EC) DUT_THERMS = 36, // // 요약: // Inches of water per 100 feet DUT_INCHES_OF_WATER_PER_100FT = 37, // // 요약: // pascal per meter (N/m) DUT_PASCALS_PER_METER = 38, // // 요약: // watt (W) DUT_WATTS = 39, // // 요약: // kilowatt (kW) DUT_KILOWATTS = 40, // // 요약: // British thermal unit[IT] per second (Btu[IT]/s) DUT_BRITISH_THERMAL_UNITS_PER_SECOND = 41, // // 요약: // British thermal unit[IT] per hour (Btu[IT]/h) DUT_BRITISH_THERMAL_UNITS_PER_HOUR = 42, // // 요약: // calorie[IT] per second (cal[IT]/s) DUT_CALORIES_PER_SECOND = 43, // // 요약: // kilocalorie[IT] per second (kcal[IT]/s) DUT_KILOCALORIES_PER_SECOND = 44, // // 요약: // watt per square foot (W/ft²) DUT_WATTS_PER_SQUARE_FOOT = 45, // // 요약: // watt per square meter (W/m²) DUT_WATTS_PER_SQUARE_METER = 46, // // 요약: // inch of water (60.8°F) DUT_INCHES_OF_WATER = 47, // // 요약: // pascal (Pa) DUT_PASCALS = 48, // // 요약: // kilopascal (kPa) DUT_KILOPASCALS = 49, // // 요약: // megapascal (MPa) DUT_MEGAPASCALS = 50, // // 요약: // pound-force per square inch (psi) (lbf/in2) DUT_POUNDS_FORCE_PER_SQUARE_INCH = 51, // // 요약: // inch of mercury conventional (inHg) DUT_INCHES_OF_MERCURY = 52, // // 요약: // millimeter of mercury conventional (mmHg) DUT_MILLIMETERS_OF_MERCURY = 53, // // 요약: // atmosphere standard (atm) DUT_ATMOSPHERES = 54, // // 요약: // bar (bar) DUT_BARS = 55, // // 요약: // degree Fahrenheit (°F) DUT_FAHRENHEIT = 56, // // 요약: // degree Celsius (°C) DUT_CELSIUS = 57, // // 요약: // kelvin (K) DUT_KELVIN = 58, // // 요약: // degree Rankine (°R) DUT_RANKINE = 59, // // 요약: // foot per minute (ft/min) DUT_FEET_PER_MINUTE = 60, // // 요약: // meter per second (m/s) DUT_METERS_PER_SECOND = 61, // // 요약: // centimeter per minute (cm/min) DUT_CENTIMETERS_PER_MINUTE = 62, // // 요약: // cubic foot per minute (ft³/min) DUT_CUBIC_FEET_PER_MINUTE = 63, // // 요약: // liter per second (L/s) DUT_LITERS_PER_SECOND = 64, // // 요약: // cubic meter per second (m³/s) DUT_CUBIC_METERS_PER_SECOND = 65, // // 요약: // cubic meters per hour (m³/h) DUT_CUBIC_METERS_PER_HOUR = 66, // // 요약: // gallon (U.S.) per minute (gpm) (gal/min) DUT_GALLONS_US_PER_MINUTE = 67, // // 요약: // gallon (U.S.) per hour (gph) (gal/h) DUT_GALLONS_US_PER_HOUR = 68, // // 요약: // ampere (A) DUT_AMPERES = 69, // // 요약: // kiloampere (kA) DUT_KILOAMPERES = 70, // // 요약: // milliampere (mA) DUT_MILLIAMPERES = 71, // // 요약: // volt (V) DUT_VOLTS = 72, // // 요약: // kilovolt (kV) DUT_KILOVOLTS = 73, // // 요약: // millivolt (mV) DUT_MILLIVOLTS = 74, // // 요약: // hertz (Hz) DUT_HERTZ = 75, DUT_CYCLES_PER_SECOND = 76, // // 요약: // lux (lx) DUT_LUX = 77, // // 요약: // footcandle DUT_FOOTCANDLES = 78, // // 요약: // footlambert DUT_FOOTLAMBERTS = 79, // // 요약: // candela per square meter (cd/m²) DUT_CANDELAS_PER_SQUARE_METER = 80, // // 요약: // candela (cd) DUT_CANDELAS = 81, // // 요약: // obsolete DUT_CANDLEPOWER = 82, // // 요약: // lumen (lm) DUT_LUMENS = 83, DUT_VOLT_AMPERES = 84, DUT_KILOVOLT_AMPERES = 85, // // 요약: // horsepower (550 ft · lbf/s) DUT_HORSEPOWER = 86, DUT_NEWTONS = 87, DUT_DECANEWTONS = 88, DUT_KILONEWTONS = 89, DUT_MEGANEWTONS = 90, DUT_KIPS = 91, DUT_KILOGRAMS_FORCE = 92, DUT_TONNES_FORCE = 93, DUT_POUNDS_FORCE = 94, DUT_NEWTONS_PER_METER = 95, DUT_DECANEWTONS_PER_METER = 96, DUT_KILONEWTONS_PER_METER = 97, DUT_MEGANEWTONS_PER_METER = 98, DUT_KIPS_PER_FOOT = 99, DUT_KILOGRAMS_FORCE_PER_METER = 100, DUT_TONNES_FORCE_PER_METER = 101, DUT_POUNDS_FORCE_PER_FOOT = 102, DUT_NEWTONS_PER_SQUARE_METER = 103, DUT_DECANEWTONS_PER_SQUARE_METER = 104, DUT_KILONEWTONS_PER_SQUARE_METER = 105, DUT_MEGANEWTONS_PER_SQUARE_METER = 106, DUT_KIPS_PER_SQUARE_FOOT = 107, DUT_KILOGRAMS_FORCE_PER_SQUARE_METER = 108, DUT_TONNES_FORCE_PER_SQUARE_METER = 109, DUT_POUNDS_FORCE_PER_SQUARE_FOOT = 110, DUT_NEWTON_METERS = 111, DUT_DECANEWTON_METERS = 112, DUT_KILONEWTON_METERS = 113, DUT_MEGANEWTON_METERS = 114, DUT_KIP_FEET = 115, DUT_KILOGRAM_FORCE_METERS = 116, DUT_TONNE_FORCE_METERS = 117, DUT_POUND_FORCE_FEET = 118, DUT_METERS_PER_KILONEWTON = 119, DUT_FEET_PER_KIP = 120, DUT_SQUARE_METERS_PER_KILONEWTON = 121, DUT_SQUARE_FEET_PER_KIP = 122, DUT_CUBIC_METERS_PER_KILONEWTON = 123, DUT_CUBIC_FEET_PER_KIP = 124, DUT_INV_KILONEWTONS = 125, DUT_INV_KIPS = 126, // // 요약: // foot of water conventional (ftH2O) per 100 ft DUT_FEET_OF_WATER_PER_100FT = 127, // // 요약: // foot of water conventional (ftH2O) DUT_FEET_OF_WATER = 128, // // 요약: // pascal second (Pa · s) DUT_PASCAL_SECONDS = 129, // // 요약: // pound per foot second (lb/(ft · s)) DUT_POUNDS_MASS_PER_FOOT_SECOND = 130, // // 요약: // centipoise (cP) DUT_CENTIPOISES = 131, // // 요약: // foot per second (ft/s) DUT_FEET_PER_SECOND = 132, DUT_KIPS_PER_SQUARE_INCH = 133, // // 요약: // kilnewtons per cubic meter (kN/m³) DUT_KILONEWTONS_PER_CUBIC_METER = 134, // // 요약: // pound per cubic foot (kip/ft³) DUT_POUNDS_FORCE_PER_CUBIC_FOOT = 135, // // 요약: // pound per cubic foot (kip/in³) DUT_KIPS_PER_CUBIC_INCH = 136, DUT_INV_FAHRENHEIT = 137, DUT_INV_CELSIUS = 138, DUT_NEWTON_METERS_PER_METER = 139, DUT_DECANEWTON_METERS_PER_METER = 140, DUT_KILONEWTON_METERS_PER_METER = 141, DUT_MEGANEWTON_METERS_PER_METER = 142, DUT_KIP_FEET_PER_FOOT = 143, DUT_KILOGRAM_FORCE_METERS_PER_METER = 144, DUT_TONNE_FORCE_METERS_PER_METER = 145, DUT_POUND_FORCE_FEET_PER_FOOT = 146, // // 요약: // pound per foot hour (lb/(ft · h)) DUT_POUNDS_MASS_PER_FOOT_HOUR = 147, DUT_KIPS_PER_INCH = 148, // // 요약: // pound per cubic foot (kip/ft³) DUT_KIPS_PER_CUBIC_FOOT = 149, DUT_KIP_FEET_PER_DEGREE = 150, DUT_KILONEWTON_METERS_PER_DEGREE = 151, DUT_KIP_FEET_PER_DEGREE_PER_FOOT = 152, DUT_KILONEWTON_METERS_PER_DEGREE_PER_METER = 153, // // 요약: // watt per square meter kelvin (W/(m² · K)) DUT_WATTS_PER_SQUARE_METER_KELVIN = 154, // // 요약: // British thermal unit[IT] per hour square foot degree Fahrenheit (Btu[IT]/(h · // ft² · °F) DUT_BRITISH_THERMAL_UNITS_PER_HOUR_SQUARE_FOOT_FAHRENHEIT = 155, // // 요약: // cubic foot per minute square foot DUT_CUBIC_FEET_PER_MINUTE_SQUARE_FOOT = 156, // // 요약: // liter per second square meter DUT_LITERS_PER_SECOND_SQUARE_METER = 157, DUT_RATIO_10 = 158, DUT_RATIO_12 = 159, DUT_SLOPE_DEGREES = 160, DUT_RISE_OVER_INCHES = 161, DUT_RISE_OVER_FOOT = 162, DUT_RISE_OVER_MMS = 163, // // 요약: // watt per cubic foot (W/m³) DUT_WATTS_PER_CUBIC_FOOT = 164, // // 요약: // watt per cubic meter (W/m³) DUT_WATTS_PER_CUBIC_METER = 165, // // 요약: // British thermal unit[IT] per hour square foot (Btu[IT]/(h · ft²) DUT_BRITISH_THERMAL_UNITS_PER_HOUR_SQUARE_FOOT = 166, // // 요약: // British thermal unit[IT] per hour cubic foot (Btu[IT]/(h · ft³) DUT_BRITISH_THERMAL_UNITS_PER_HOUR_CUBIC_FOOT = 167, // // 요약: // Ton of refrigeration (12 000 Btu[IT]/h) DUT_TON_OF_REFRIGERATION = 168, // // 요약: // cubic foot per minute cubic foot DUT_CUBIC_FEET_PER_MINUTE_CUBIC_FOOT = 169, // // 요약: // liter per second cubic meter DUT_LITERS_PER_SECOND_CUBIC_METER = 170, // // 요약: // cubic foot per minute ton of refrigeration DUT_CUBIC_FEET_PER_MINUTE_TON_OF_REFRIGERATION = 171, // // 요약: // liter per second kilowatt DUT_LITERS_PER_SECOND_KILOWATTS = 172, // // 요약: // square foot per ton of refrigeration DUT_SQUARE_FEET_PER_TON_OF_REFRIGERATION = 173, // // 요약: // square meter per kilowatt DUT_SQUARE_METERS_PER_KILOWATTS = 174, DUT_CURRENCY = 175, DUT_LUMENS_PER_WATT = 176, // // 요약: // square foot per thousand British thermal unit[IT] per hour DUT_SQUARE_FEET_PER_THOUSAND_BRITISH_THERMAL_UNITS_PER_HOUR = 177, DUT_KILONEWTONS_PER_SQUARE_CENTIMETER = 178, DUT_NEWTONS_PER_SQUARE_MILLIMETER = 179, DUT_KILONEWTONS_PER_SQUARE_MILLIMETER = 180, DUT_RISE_OVER_120_INCHES = 181, DUT_1_RATIO = 182, DUT_RISE_OVER_10_FEET = 183, DUT_HOUR_SQUARE_FOOT_FAHRENHEIT_PER_BRITISH_THERMAL_UNIT = 184, DUT_SQUARE_METER_KELVIN_PER_WATT = 185, DUT_BRITISH_THERMAL_UNIT_PER_FAHRENHEIT = 186, DUT_JOULES_PER_KELVIN = 187, DUT_KILOJOULES_PER_KELVIN = 188, // // 요약: // kilograms (kg) DUT_KILOGRAMS_MASS = 189, // // 요약: // tonnes (t) DUT_TONNES_MASS = 190, // // 요약: // pounds (lb) DUT_POUNDS_MASS = 191, // // 요약: // meters per second squared (m/s²) DUT_METERS_PER_SECOND_SQUARED = 192, // // 요약: // kilometers per second squared (km/s²) DUT_KILOMETERS_PER_SECOND_SQUARED = 193, // // 요약: // inches per second squared (in/s²) DUT_INCHES_PER_SECOND_SQUARED = 194, // // 요약: // feet per second squared (ft/s²) DUT_FEET_PER_SECOND_SQUARED = 195, // // 요약: // miles per second squared (mi/s²) DUT_MILES_PER_SECOND_SQUARED = 196, // // 요약: // feet to the fourth power (ft^4) DUT_FEET_TO_THE_FOURTH_POWER = 197, // // 요약: // inches to the fourth power (in^4) DUT_INCHES_TO_THE_FOURTH_POWER = 198, // // 요약: // millimeters to the fourth power (mm^4) DUT_MILLIMETERS_TO_THE_FOURTH_POWER = 199, // // 요약: // centimeters to the fourth power (cm^4) DUT_CENTIMETERS_TO_THE_FOURTH_POWER = 200, // // 요약: // Meters to the fourth power (m^4) DUT_METERS_TO_THE_FOURTH_POWER = 201, // // 요약: // feet to the sixth power (ft^6) DUT_FEET_TO_THE_SIXTH_POWER = 202, // // 요약: // inches to the sixth power (in^6) DUT_INCHES_TO_THE_SIXTH_POWER = 203, // // 요약: // millimeters to the sixth power (mm^6) DUT_MILLIMETERS_TO_THE_SIXTH_POWER = 204, // // 요약: // centimeters to the sixth power (cm^6) DUT_CENTIMETERS_TO_THE_SIXTH_POWER = 205, // // 요약: // meters to the sixth power (m^6) DUT_METERS_TO_THE_SIXTH_POWER = 206, // // 요약: // square feet per foot (ft²/ft) DUT_SQUARE_FEET_PER_FOOT = 207, // // 요약: // square inches per foot (in²/ft) DUT_SQUARE_INCHES_PER_FOOT = 208, // // 요약: // square millimeters per meter (mm²/m) DUT_SQUARE_MILLIMETERS_PER_METER = 209, // // 요약: // square centimeters per meter (cm²/m) DUT_SQUARE_CENTIMETERS_PER_METER = 210, // // 요약: // square meters per meter (m²/m) DUT_SQUARE_METERS_PER_METER = 211, // // 요약: // kilograms per meter (kg/m) DUT_KILOGRAMS_MASS_PER_METER = 212, // // 요약: // pounds per foot (lb/ft) DUT_POUNDS_MASS_PER_FOOT = 213, // // 요약: // radians DUT_RADIANS = 214, // // 요약: // grads DUT_GRADS = 215, // // 요약: // radians per second DUT_RADIANS_PER_SECOND = 216, // // 요약: // millisecond DUT_MILISECONDS = 217, // // 요약: // second DUT_SECONDS = 218, // // 요약: // minutes DUT_MINUTES = 219, // // 요약: // hours DUT_HOURS = 220, // // 요약: // kilometers per hour DUT_KILOMETERS_PER_HOUR = 221, // // 요약: // miles per hour DUT_MILES_PER_HOUR = 222, // // 요약: // kilojoules DUT_KILOJOULES = 223, // // 요약: // kilograms per square meter (kg/m²) DUT_KILOGRAMS_MASS_PER_SQUARE_METER = 224, // // 요약: // pounds per square foot (lb/ft²) DUT_POUNDS_MASS_PER_SQUARE_FOOT = 225, // // 요약: // Watts per meter kelvin (W/(m·K)) DUT_WATTS_PER_METER_KELVIN = 226, // // 요약: // Joules per gram Celsius (J/(g·°C)) DUT_JOULES_PER_GRAM_CELSIUS = 227, // // 요약: // Joules per gram (J/g) DUT_JOULES_PER_GRAM = 228, // // 요약: // Nanograms per pascal second square meter (ng/(Pa·s·m²)) DUT_NANOGRAMS_PER_PASCAL_SECOND_SQUARE_METER = 229, // // 요약: // Ohm meters DUT_OHM_METERS = 230, // // 요약: // BTU per hour foot Fahrenheit (BTU/(h·ft·°F)) DUT_BRITISH_THERMAL_UNITS_PER_HOUR_FOOT_FAHRENHEIT = 231, // // 요약: // BTU per pound Fahrenheit (BTU/(lb·°F)) DUT_BRITISH_THERMAL_UNITS_PER_POUND_FAHRENHEIT = 232, // // 요약: // BTU per pound (BTU/lb) DUT_BRITISH_THERMAL_UNITS_PER_POUND = 233, // // 요약: // Grains per hour square foot inch mercury (gr/(h·ft²·inHg)) DUT_GRAINS_PER_HOUR_SQUARE_FOOT_INCH_MERCURY = 234, // // 요약: // Per mille or per thousand(‰) DUT_PER_MILLE = 235, // // 요약: // Decimeters DUT_DECIMETERS = 236, // // 요약: // Joules per kilogram Celsius (J/(kg·°C)) DUT_JOULES_PER_KILOGRAM_CELSIUS = 237, // // 요약: // Micrometers per meter Celsius (um/(m·°C)) DUT_MICROMETERS_PER_METER_CELSIUS = 238, // // 요약: // Microinches per inch Fahrenheit (uin/(in·°F)) DUT_MICROINCHES_PER_INCH_FAHRENHEIT = 239, // // 요약: // US tonnes (T, Tons, ST) DUT_USTONNES_MASS = 240, // // 요약: // US tonnes (Tonsf, STf) DUT_USTONNES_FORCE = 241, // // 요약: // liters per minute (L/min) DUT_LITERS_PER_MINUTE = 242, // // 요약: // degree Fahrenheit difference (delta °F) DUT_FAHRENHEIT_DIFFERENCE = 243, // // 요약: // degree Celsius difference (delta °C) DUT_CELSIUS_DIFFERENCE = 244, // // 요약: // kelvin difference (delta K) DUT_KELVIN_DIFFERENCE = 245, // // 요약: // degree Rankine difference (delta °R) DUT_RANKINE_DIFFERENCE = 246 } public class Unit { #region Methods /// /// Convert the value get from RevitAPI to the value indicated by DisplayUnitType /// /// DisplayUnitType indicates unit of target value /// value get from RevitAPI /// Target value public static double CovertFromAPI(ForgeTypeId to, double value) { return value *= ImperialDutRatio(to); } /// /// Convert a value indicated by DisplayUnitType to the value used by RevitAPI /// /// Value to be converted /// DisplayUnitType indicates the unit of the value to be converted /// Target value public static double CovertToAPI(double value, ForgeTypeId from) { return value /= ImperialDutRatio(from); } /// /// Get ratio between value in RevitAPI and value to display indicated by DisplayUnitType /// /// DisplayUnitType indicates display unit type /// Ratio private static double ImperialDutRatio(ForgeTypeId UTid) { ForgeTypeId[] LstForge = new ForgeTypeId[] {UnitTypeId.Feet,UnitTypeId.FeetFractionalInches,UnitTypeId.Inches,UnitTypeId.FractionalInches ,UnitTypeId.Meters,UnitTypeId.Centimeters,UnitTypeId.Millimeters,UnitTypeId.MetersCentimeters}; int idx = Array.IndexOf(LstForge, UTid); switch (idx) { case 0: return 1; case 1: return 1; case 2: return 12; case 3: return 12; case 4: return 0.3048; case 5: return 30.48; case 6: return 304.8; case 7: return 0.3048; default: return 1; } } /// 피트 -> MM 변환 public static double FeetToMM(double value) { if (value == 0) return 0; return value *= 304.8; } /// MM -> 피트 변환 public static double MMToFeet(double value) { if (value == 0) return 0; return value /= 304.8; } #endregion } }