public static string GetSymbol(IIfcDerivedUnit du) { var symbol = du.UnitType switch { IfcDerivedUnitEnum.PHUNIT => "pH", IfcDerivedUnitEnum.SOUNDPOWERUNIT => "W", IfcDerivedUnitEnum.SOUNDPOWERLEVELUNIT => "db", IfcDerivedUnitEnum.SOUNDPRESSUREUNIT => "Pa", IfcDerivedUnitEnum.SOUNDPRESSURELEVELUNIT => "db", _ => string.Empty }; if (!string.IsNullOrEmpty(symbol)) { return(symbol); } var sb = new StringBuilder(); foreach (var item in du.Elements) { var unit = GetSymbol(item.Unit); sb.Append(unit); var exponent = GetExponentSymbol(item.Exponent); sb.Append(exponent); } return(sb.ToString()); }
static bool getDerivedUnitRepStr(IIfcUnit unitDef, out IfcDerivedUnitEnum 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 = IfcDerivedUnitEnum.USERDEFINED; // initial value IIfcDerivedUnit derivedUnit = unitDef as IIfcDerivedUnit; unitType = derivedUnit.UnitType; unitRepStr = string.Empty; IList <string> positiveExpUnits = new List <string>(); IList <string> negativeExpUnits = new List <string>(); foreach (IIfcDerivedUnitElement dUnitElem in derivedUnit.Elements) { IfcUnitEnum elemUnitType; string elemUnitRepStr = string.Empty; int exponent = (int)dUnitElem.Exponent; if (getNamedUnitRepStr(dUnitElem.Unit, out elemUnitType, out elemUnitRepStr)) { if (exponent >= 0) { if (exponent > 1) { elemUnitRepStr = elemUnitRepStr + "^" + exponent.ToString(); } //elemUnitRepStr = elemUnitRepStr + unicodeSuperScript(exponent); positiveExpUnits.Add(elemUnitRepStr); } else { if (exponent < -1) { elemUnitRepStr = elemUnitRepStr + "^" + Math.Abs(exponent).ToString(); } //elemUnitRepStr = elemUnitRepStr + unicodeSuperScript(Math.Abs(exponent)); negativeExpUnits.Add(elemUnitRepStr); } } } if (positiveExpUnits.Count > 0) { foreach (string elemUnit in positiveExpUnits) { BIMRLCommon.appendToString(elemUnit, ".", ref unitRepStr); //BAIFCCommon.appendToString(elemUnit, "\u22C5", ref negUnitRepStr); } } else { if (negativeExpUnits.Count > 0) { unitRepStr = "1"; } } string negUnitRepStr = string.Empty; if (negativeExpUnits.Count > 0) { foreach (string elemUnit in negativeExpUnits) { BIMRLCommon.appendToString(elemUnit, "ยท", ref negUnitRepStr); //BAIFCCommon.appendToString(elemUnit, "\u22C5", ref negUnitRepStr); } } if (!string.IsNullOrEmpty(negUnitRepStr)) { unitRepStr += "/" + negUnitRepStr; } if (!string.IsNullOrEmpty(unitRepStr)) { return(true); } else { return(false); } }