public static AbstractTextElement CreateTextElement(TextElementType textElementType, string value = "") { switch (textElementType) { case TextElementType.TextUnit: return(new TextUnit(value)); case TextElementType.TextElementCollection: return(new TextElementCollection()); case TextElementType.Paragraph: if (value.Length == 0) { return(new Paragraph()); } else { var paragraph = new Paragraph(); paragraph.AddTextElement(new TextUnit(value)); return(paragraph); } default: //here can not be executed. return(null); } }
internal ElementIndexCache(int index, TextElementType element) { // index == -1/element == null means "empty". Invariant.Assert(index == -1 || element != null); _index = index; _element = element; }
Stream(ArrayList data, TextElementType textAttr) { data.Add(new Snoop.Data.ClassSeparator(typeof(TextElementType))); // no data at this level TextNoteType textNoteAttr = textAttr as TextNoteType; if (textNoteAttr != null) { Stream(data, textNoteAttr); return; } }
Stream(ArrayList data, LineAndTextAttrSymbol lineAttr) { data.Add(new Snoop.Data.ClassSeparator(typeof(LineAndTextAttrSymbol))); GridType gridType = lineAttr as GridType; if (gridType != null) { Stream(data, gridType); return; } TextElementType textAttr = lineAttr as TextElementType; if (textAttr != null) { Stream(data, textAttr); return; } }
/// <summary> /// Exports text note elements. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="textNote"> /// The text note element. /// </param> /// <param name="productWrapper"> /// The ProductWrapper. /// </param> public static void Export(ExporterIFC exporterIFC, TextNote textNote, ProductWrapper productWrapper) { // Check the intended IFC entity or type name is in the exclude list specified in the UI string predefinedType = null; IFCExportInfoPair exportType = ExporterUtil.GetProductExportType(exporterIFC, textNote, out predefinedType); if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(exportType.ExportInstance)) { return; } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { string textString = textNote.Text; if (String.IsNullOrEmpty(textString)) { throw new Exception("TextNote does not have test string."); } ElementId symId = textNote.GetTypeId(); if (symId == ElementId.InvalidElementId) { throw new Exception("TextNote does not have valid type id."); } PresentationStyleAssignmentCache cache = ExporterCacheManager.PresentationStyleAssignmentCache; IFCAnyHandle presHnd = cache.Find(symId); if (IFCAnyHandleUtil.IsNullOrHasNoValue(presHnd)) { TextElementType textElemType = textNote.Symbol; CreatePresentationStyleAssignmentForTextElementType(exporterIFC, textElemType, cache); presHnd = cache.Find(symId); if (IFCAnyHandleUtil.IsNullOrHasNoValue(presHnd)) { throw new Exception("Failed to create presentation style assignment for TextElementType."); } } HashSet <IFCAnyHandle> presHndSet = new HashSet <IFCAnyHandle>(); presHndSet.Add(presHnd); using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, textNote)) { const double planScale = 100.0; // currently hardwired. XYZ orig = UnitUtil.ScaleLength(textNote.Coord); XYZ yDir = textNote.UpDirection; XYZ xDir = textNote.BaseDirection; XYZ zDir = xDir.CrossProduct(yDir); double sizeX = UnitUtil.ScaleLength(textNote.Width * planScale); double sizeY = UnitUtil.ScaleLength(textNote.Height * planScale); // When we display text on screen, we "flip" it if the xDir is negative with relation to // the X-axis. So if it is, we'll flip x and y. bool flipOrig = false; if (xDir.X < 0) { xDir = xDir.Multiply(-1.0); yDir = yDir.Multiply(-1.0); flipOrig = true; } // xFactor, yFactor only used if flipOrig. double xFactor = 0.0, yFactor = 0.0; string boxAlignment = ConvertTextNoteAlignToBoxAlign(textNote, out xFactor, out yFactor); // modify the origin to match the alignment. In Revit, the origin is at the top-left (unless flipped, // then bottom-right). if (flipOrig) { orig = orig.Add(xDir.Multiply(sizeX * xFactor)); orig = orig.Add(yDir.Multiply(sizeY * yFactor)); } IFCAnyHandle origin = ExporterUtil.CreateAxis(file, orig, zDir, xDir); IFCAnyHandle extent = IFCInstanceExporter.CreatePlanarExtent(file, sizeX, sizeY); IFCAnyHandle repItemHnd = IFCInstanceExporter.CreateTextLiteralWithExtent(file, textString, origin, Toolkit.IFCTextPath.Left, extent, boxAlignment); IFCAnyHandle annoTextOccHnd = IFCInstanceExporter.CreateStyledItem(file, repItemHnd, presHndSet, null); ElementId catId = textNote.Category != null ? textNote.Category.Id : ElementId.InvalidElementId; HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>(); bodyItems.Add(repItemHnd); IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateAnnotationSetRep(exporterIFC, textNote, catId, exporterIFC.Get2DContextHandle(), bodyItems); if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd)) { throw new Exception("Failed to create shape representation."); } IList <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>(); shapeReps.Add(bodyRepHnd); IFCAnyHandle prodShapeHnd = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps); IFCAnyHandle instHnd; if (exportType.ExportInstance == Common.Enums.IFCEntityType.IfcAnnotation) { instHnd = IFCInstanceExporter.CreateAnnotation(exporterIFC, textNote, GUIDUtil.CreateGUID(), ExporterCacheManager.OwnerHistoryHandle, setter.LocalPlacement, prodShapeHnd); } else { instHnd = IFCInstanceExporter.CreateGenericIFCEntity(exportType, exporterIFC, textNote, GUIDUtil.CreateGUID(), ExporterCacheManager.OwnerHistoryHandle, setter.LocalPlacement, prodShapeHnd); } productWrapper.AddAnnotation(instHnd, setter.LevelInfo, true); } tr.Commit(); } }
/// <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); }
/// <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); }
private void Stream(ArrayList data, TextElementType textAttr) { data.Add(new Snoop.Data.ClassSeparator(typeof(TextElementType))); // no data at this level TextNoteType textNoteAttr = textAttr as TextNoteType; if (textNoteAttr != null) { Stream(data, textNoteAttr); return; } }
/// <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); }
public AbstractTextElement(TextElementType textElementType) { TextElementType = textElementType; CustomProperty = new PropertyConfiguration(); }
// Token: 0x060085CB RID: 34251 RVA: 0x0024AF86 File Offset: 0x00249186 internal ElementIndexCache(int index, TextElementType element) { Invariant.Assert(index == -1 || element != null); this._index = index; this._element = element; }