/// <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);
        }
Exemple #2
0
        /// <summary>
        /// Get the handles of Grid Axes.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="sameDirectionAxes">The grid axes in the same direction of one level.</param>
        /// <param name="representations">The representation of grid axis.</param>
        /// <returns>The list of handles of grid axes.</returns>
        private static List <IFCAnyHandle> CreateIFCGridAxisAndRepresentations(ExporterIFC exporterIFC, ProductWrapper productWrapper, IList <Grid> sameDirectionAxes,
                                                                               IList <IFCAnyHandle> representations, GridRepresentationData gridRepresentationData)
        {
            if (sameDirectionAxes.Count == 0)
            {
                return(null);
            }

            IDictionary <ElementId, List <IFCAnyHandle> > gridAxisMap = new Dictionary <ElementId, List <IFCAnyHandle> >();
            IDictionary <ElementId, List <IFCAnyHandle> > gridRepMap  = new Dictionary <ElementId, List <IFCAnyHandle> >();

            IFCFile ifcFile  = exporterIFC.GetFile();
            Grid    baseGrid = sameDirectionAxes[0];

            Transform lcs = Transform.Identity;

            List <IFCAnyHandle> ifcGridAxes = new List <IFCAnyHandle>();

            foreach (Grid grid in sameDirectionAxes)
            {
                // Because the IfcGrid is a collection of Revit Grids, any one of them can override the IFC CAD Layer.
                // We will take the first name, and not do too much checking.
                if (string.IsNullOrWhiteSpace(gridRepresentationData.m_IFCCADLayer))
                {
                    ParameterUtil.GetStringValueFromElementOrSymbol(grid, "IFCCadLayer", out gridRepresentationData.m_IFCCADLayer);
                }

                // Get the handle of curve.
                XYZ          projectionDirection = lcs.BasisZ;
                IFCAnyHandle axisCurve;
                if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
                {
                    axisCurve = GeometryUtil.CreatePolyCurveFromCurve(exporterIFC, grid.Curve, lcs, projectionDirection);
                }
                else
                {
                    IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, lcs, projectionDirection, false);
                    ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, grid.Curve, XYZ.Zero, false);
                    IList <IFCAnyHandle> curves = info.GetCurves();
                    if (curves.Count != 1)
                    {
                        throw new Exception("IFC: expected 1 curve when export curve element.");
                    }

                    axisCurve = curves[0];
                }

                bool sameSense = true;
                if (baseGrid.Curve is Line)
                {
                    Line baseLine = baseGrid.Curve as Line;
                    Line axisLine = grid.Curve as Line;
                    sameSense = (axisLine.Direction.IsAlmostEqualTo(baseLine.Direction));
                }

                IFCAnyHandle ifcGridAxis = IFCInstanceExporter.CreateGridAxis(ifcFile, grid.Name, axisCurve, sameSense);
                ifcGridAxes.Add(ifcGridAxis);

                HashSet <IFCAnyHandle> AxisCurves = new HashSet <IFCAnyHandle>();
                AxisCurves.Add(axisCurve);

                IFCAnyHandle repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(ifcFile, AxisCurves);

                // get the weight and color from the GridType to create the curve style.
                GridType gridType = grid.Document.GetElement(grid.GetTypeId()) as GridType;

                IFCData curveWidth = null;
                if (ExporterCacheManager.ExportOptionsCache.ExportAnnotations)
                {
                    int    outWidth;
                    double width =
                        (ParameterUtil.GetIntValueFromElement(gridType, BuiltInParameter.GRID_END_SEGMENT_WEIGHT, out outWidth) != null) ? outWidth : 1;
                    curveWidth = IFCDataUtil.CreateAsPositiveLengthMeasure(width);
                }

                if (!ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
                {
                    int outColor;
                    int color =
                        (ParameterUtil.GetIntValueFromElement(gridType, BuiltInParameter.GRID_END_SEGMENT_COLOR, out outColor) != null) ? outColor : 0;
                    double blueVal  = 0.0;
                    double greenVal = 0.0;
                    double redVal   = 0.0;
                    GeometryUtil.GetRGBFromIntValue(color, out blueVal, out greenVal, out redVal);
                    IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(ifcFile, null, redVal, greenVal, blueVal);

                    BodyExporter.CreateCurveStyleForRepItem(exporterIFC, repItemHnd, curveWidth, colorHnd);
                }

                HashSet <IFCAnyHandle> curveSet = new HashSet <IFCAnyHandle>();
                curveSet.Add(repItemHnd);

                gridRepresentationData.m_Grids.Add(grid);
                gridRepresentationData.m_curveSets.Add(curveSet);
            }

            return(ifcGridAxes);
        }