/// <summary> /// Creates IfcPresentationStyleAssignment for text element type. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="textElementType"> /// The text note element type. /// </param> /// <param name="cache"> /// The cache of IfcPresentationStyleAssignment. /// </param> static void CreatePresentationStyleAssignmentForTextElementType(ExporterIFC exporterIFC, TextElementType textElementType, PresentationStyleAssignmentCache cache) { IFCFile file = exporterIFC.GetFile(); Parameter fontNameParam = textElementType.get_Parameter(BuiltInParameter.TEXT_FONT); string fontName = (fontNameParam != null && fontNameParam.StorageType == StorageType.String) ? fontNameParam.AsString() : null; Parameter fontSizeParam = textElementType.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); IFCMeasureValue ifcFontSize = IFCMeasureValue.Create(fontSize); IFCLabel ifcPreDefinedItemName = IFCLabel.Create("Text Font"); IFCLabel ifcFontName = IFCLabel.Create(fontName); IList<IFCLabel> fontNameList = new List<IFCLabel>(); fontNameList.Add(ifcFontName); IFCAnyHandle textSyleFontModelHnd = file.CreateTextStyleFontModel(ifcPreDefinedItemName, fontNameList, IFCLabel.Create(), IFCLabel.Create(), IFCLabel.Create(), ifcFontSize); Parameter fontColorParam = textElementType.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 = file.CreateColourRgb(IFCLabel.Create(), redVal, greenVal, blueVal); IFCAnyHandle fontColorHnd = file.CreateTextStyleForDefinedFont(colorHnd, IFCAnyHandle.Create()); IFCLabel ifcAttrName = IFCLabel.Create(textElementType.Name); IFCAnyHandle textStyleHnd = file.CreateTextStyle(ifcAttrName, fontColorHnd, IFCAnyHandle.Create(), textSyleFontModelHnd); if (!textStyleHnd.HasValue) return; ICollection<IFCAnyHandle> presStyleSet = new System.Collections.ObjectModel.Collection<IFCAnyHandle>(); presStyleSet.Add(textStyleHnd); IFCAnyHandle presStyleHnd = file.CreatePresentationStyleAssignment(presStyleSet); if (!presStyleHnd.HasValue) return; cache.Register(textElementType.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)) fontName = null; double fontSize; if (!ParameterUtil.GetDoubleValueFromElement(textElemType, BuiltInParameter.TEXT_SIZE, out fontSize)) fontSize = -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)); 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); }