/// <summary> /// Creates IfcPresentationStyleAssignment for text element type. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="textElemType"> /// The text note element type. /// </param> /// <param name="cache"> /// The cache of IfcPresentationStyleAssignment. /// </param> static void CreatePresentationStyleAssignmentForTextElementType(ExporterIFC exporterIFC, TextElementType textElemType, PresentationStyleAssignmentCache cache) { IFCFile file = exporterIFC.GetFile(); Parameter fontNameParam = textElemType.get_Parameter(BuiltInParameter.TEXT_FONT); string fontName = (fontNameParam != null && fontNameParam.StorageType == StorageType.String) ? fontNameParam.AsString() : null; Parameter fontSizeParam = textElemType.get_Parameter(BuiltInParameter.TEXT_SIZE); double fontSize = (fontSizeParam != null && fontSizeParam.StorageType == StorageType.Double) ? fontSizeParam.AsDouble() : -1.0; double scale = exporterIFC.LinearScale; double viewScale = 100.0; // currently hardwired. fontSize *= (scale * viewScale); string ifcPreDefinedItemName = "Text Font"; IList <string> fontNameList = new List <string>(); fontNameList.Add(fontName); IFCAnyHandle textSyleFontModelHnd = IFCInstanceExporter.CreateTextStyleFontModel(file, ifcPreDefinedItemName, fontNameList, null, null, null, IFCDataUtil.CreateAsPositiveLengthMeasure(fontSize)); Parameter fontColorParam = textElemType.get_Parameter(BuiltInParameter.LINE_COLOR); int color = (fontColorParam != null && fontColorParam.StorageType == StorageType.Integer) ? fontColorParam.AsInteger() : 0; double blueVal = ((double)((color & 0xff0000) >> 16)) / 255.0; double greenVal = ((double)((color & 0xff00) >> 8)) / 255.0; double redVal = ((double)(color & 0xff)) / 255.0; IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(file, null, redVal, greenVal, blueVal); IFCAnyHandle fontColorHnd = IFCInstanceExporter.CreateTextStyleForDefinedFont(file, colorHnd, null); string ifcAttrName = textElemType.Name; IFCAnyHandle textStyleHnd = IFCInstanceExporter.CreateTextStyle(file, textElemType.Name, fontColorHnd, null, textSyleFontModelHnd); if (IFCAnyHandleUtil.IsNullOrHasNoValue(textStyleHnd)) { return; } HashSet <IFCAnyHandle> presStyleSet = new HashSet <IFCAnyHandle>(); presStyleSet.Add(textStyleHnd); IFCAnyHandle presStyleHnd = IFCInstanceExporter.CreatePresentationStyleAssignment(file, presStyleSet); if (IFCAnyHandleUtil.IsNullOrHasNoValue(presStyleHnd)) { return; } cache.Register(textElemType.Id, presStyleHnd); }
/// <summary> /// Creates IfcPresentationStyleAssignment for text element type. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="textElemType"> /// The text note element type. /// </param> /// <param name="cache"> /// The cache of IfcPresentationStyleAssignment. /// </param> static void CreatePresentationStyleAssignmentForTextElementType(ExporterIFC exporterIFC, TextElementType textElemType, PresentationStyleAssignmentCache cache) { IFCFile file = exporterIFC.GetFile(); string fontName; if (ParameterUtil.GetStringValueFromElement(textElemType, BuiltInParameter.TEXT_FONT, out fontName) == null) fontName = null; double fontSize; if (ParameterUtil.GetDoubleValueFromElement(textElemType, BuiltInParameter.TEXT_SIZE, out fontSize) == null) fontSize = -1.0; double viewScale = 100.0; // currently hardwired. fontSize = UnitUtil.ScaleLength(fontSize * viewScale); string ifcPreDefinedItemName = "Text Font"; IList<string> fontNameList = new List<string>(); fontNameList.Add(fontName); IFCAnyHandle textSyleFontModelHnd = IFCInstanceExporter.CreateTextStyleFontModel(file, ifcPreDefinedItemName, fontNameList, null, null, null, IFCDataUtil.CreateAsPositiveLengthMeasure(fontSize)); int color; ParameterUtil.GetIntValueFromElement(textElemType, BuiltInParameter.LINE_COLOR, out color); double blueVal = ((double)((color & 0xff0000) >> 16)) / 255.0; double greenVal = ((double)((color & 0xff00) >> 8)) / 255.0; double redVal = ((double)(color & 0xff)) / 255.0; IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(file, null, redVal, greenVal, blueVal); IFCAnyHandle fontColorHnd = IFCInstanceExporter.CreateTextStyleForDefinedFont(file, colorHnd, null); string ifcAttrName = textElemType.Name; IFCAnyHandle textStyleHnd = IFCInstanceExporter.CreateTextStyle(file, textElemType.Name, fontColorHnd, null, textSyleFontModelHnd); if (IFCAnyHandleUtil.IsNullOrHasNoValue(textStyleHnd)) return; HashSet<IFCAnyHandle> presStyleSet = new HashSet<IFCAnyHandle>(); presStyleSet.Add(textStyleHnd); IFCAnyHandle presStyleHnd = IFCInstanceExporter.CreatePresentationStyleAssignment(file, presStyleSet); if (IFCAnyHandleUtil.IsNullOrHasNoValue(presStyleHnd)) return; cache.Register(textElemType.Id, presStyleHnd); }