/// <summary>
        /// Exports an element as an annotation.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="filledRegion">The filled region element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void Export(ExporterIFC exporterIFC, FilledRegion filledRegion,
                                  GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            if (filledRegion == null || geometryElement == null)
            {
                return;
            }

            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcAnnotation;
            if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                IList <CurveLoop> boundaries = filledRegion.GetBoundaries();
                if (boundaries.Count == 0)
                {
                    return;
                }

                Plane plane = null;
                try
                {
                    plane = boundaries[0].GetPlane();
                }
                catch
                {
                    return;
                }

                Transform orientTrf           = GeometryUtil.CreateTransformFromPlane(plane);
                XYZ       projectionDirection = plane.Normal;

                IList <IList <CurveLoop> > sortedLoops = ExporterIFCUtils.SortCurveLoops(boundaries);
                if (sortedLoops.Count == 0)
                {
                    return;
                }

                FilledRegionType filledRegionType = filledRegion.Document.GetElement(filledRegion.GetTypeId()) as FilledRegionType;
                Color            color            = filledRegionType != null?CategoryUtil.GetSafeColor(filledRegionType.ForegroundPatternColor) : new Color(0, 0, 0);

                ElementId foregroundPatternId = filledRegionType != null ? filledRegionType.ForegroundPatternId : ElementId.InvalidElementId;
                ElementId categoryId          = CategoryUtil.GetSafeCategoryId(filledRegion);

                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, filledRegion, null, orientTrf))
                {
                    foreach (IList <CurveLoop> curveLoopList in sortedLoops)
                    {
                        IFCAnyHandle           outerCurve  = null;
                        HashSet <IFCAnyHandle> innerCurves = null;
                        for (int ii = 0; ii < curveLoopList.Count; ii++)
                        {
                            IFCAnyHandle ifcCurve = GeometryUtil.CreateIFCCurveFromCurveLoop(exporterIFC, curveLoopList[ii], orientTrf, projectionDirection);
                            if (ii == 0)
                            {
                                outerCurve = ifcCurve;
                            }
                            else
                            {
                                if (innerCurves == null)
                                {
                                    innerCurves = new HashSet <IFCAnyHandle>();
                                }
                                innerCurves.Add(ifcCurve);
                            }
                        }

                        IFCAnyHandle representItem = IFCInstanceExporter.CreateAnnotationFillArea(file, outerCurve, innerCurves);
                        file.CreateStyle(exporterIFC, representItem, color, foregroundPatternId);

                        HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>();
                        bodyItems.Add(representItem);
                        IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateAnnotationSetRep(exporterIFC, filledRegion, categoryId,
                                                                                            exporterIFC.Get2DContextHandle(), bodyItems);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd))
                        {
                            return;
                        }

                        List <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>();
                        shapeReps.Add(bodyRepHnd);

                        IFCAnyHandle productShape = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                        IFCAnyHandle annotation   = IFCInstanceExporter.CreateAnnotation(exporterIFC, filledRegion, GUIDUtil.CreateGUID(), ExporterCacheManager.OwnerHistoryHandle,
                                                                                         setter.LocalPlacement, productShape);

                        productWrapper.AddAnnotation(annotation, setter.LevelInfo, true);
                    }
                }

                transaction.Commit();
            }
        }
        /// <summary>
        /// Exports a curve element to IFC curve annotation.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="curveElement">
        /// The curve element to be exported.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void ExportCurveElement(ExporterIFC exporterIFC, CurveElement curveElement, GeometryElement geometryElement,
                                              ProductWrapper productWrapper)
        {
            if (geometryElement == null || !ShouldCurveElementBeExported(curveElement))
            {
                return;
            }

            SketchPlane sketchPlane = curveElement.SketchPlane;

            if (sketchPlane == null)
            {
                return;
            }

            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcAnnotation;
            if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, curveElement))
                {
                    IFCAnyHandle localPlacement = setter.LocalPlacement;
                    IFCAnyHandle axisPlacement  = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);

                    Plane planeSK      = sketchPlane.GetPlane();
                    XYZ   projDir      = planeSK.Normal;
                    XYZ   origin       = planeSK.Origin;
                    bool  useOffsetTrf = false;
                    if (projDir.IsAlmostEqualTo(XYZ.BasisZ))
                    {
                        XYZ offset = XYZ.BasisZ * setter.Offset;
                        origin -= offset;
                    }
                    else
                    {
                        useOffsetTrf = true;
                    }

                    Transform curveLCS = GeometryUtil.CreateTransformFromPlane(planeSK);
                    curveLCS.Origin = origin;

                    IList <IFCAnyHandle> curves = null;

                    if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
                    {
                        Transform trf = null;
                        if (useOffsetTrf)
                        {
                            XYZ offsetOrig = -XYZ.BasisZ * setter.Offset;
                            trf = Transform.CreateTranslation(offsetOrig);
                        }

                        curves = new List <IFCAnyHandle>();
                        //Curve curve = (geometryElement as GeometryObject) as Curve;
                        List <Curve> curvesFromGeomElem = GeometryUtil.GetCurvesFromGeometryElement(geometryElement);
                        foreach (Curve curve in curvesFromGeomElem)
                        {
                            IFCAnyHandle curveHnd = GeometryUtil.CreatePolyCurveFromCurve(exporterIFC, curve, trf);
                            //IList<int> segmentIndex = null;
                            //IList<IList<double>> pointList = GeometryUtil.PointListFromCurve(exporterIFC, curve, trf, null, out segmentIndex);

                            //// For now because of no support in creating IfcLineIndex and IfcArcIndex yet, it is set to null
                            ////IList<IList<int>> segmentIndexList = new List<IList<int>>();
                            ////segmentIndexList.Add(segmentIndex);
                            //IList<IList<int>> segmentIndexList = null;

                            //IFCAnyHandle pointListHnd = IFCInstanceExporter.CreateCartesianPointList3D(file, pointList);
                            //IFCAnyHandle curveHnd = IFCInstanceExporter.CreateIndexedPolyCurve(file, pointListHnd, segmentIndexList, false);

                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveHnd))
                            {
                                curves.Add(curveHnd);
                            }
                        }
                    }
                    else
                    {
                        IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, curveLCS, projDir, false);

                        if (useOffsetTrf)
                        {
                            XYZ       offsetOrig = -XYZ.BasisZ * setter.Offset;
                            Transform trf        = Transform.CreateTranslation(offsetOrig);
                            ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false, trf);
                        }
                        else
                        {
                            ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false);
                        }

                        curves = info.GetCurves();
                    }

                    if (curves.Count != 1)
                    {
                        throw new Exception("IFC: expected 1 curve when export curve element.");
                    }

                    HashSet <IFCAnyHandle> curveSet   = new HashSet <IFCAnyHandle>(curves);
                    IFCAnyHandle           repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(file, curveSet);

                    IFCAnyHandle curveStyle = file.CreateStyle(exporterIFC, repItemHnd);

                    CurveAnnotationCache annotationCache = ExporterCacheManager.CurveAnnotationCache;
                    IFCAnyHandle         curveAnno       = annotationCache.GetAnnotation(sketchPlane.Id, curveStyle);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveAnno))
                    {
                        AddCurvesToAnnotation(curveAnno, curves);
                    }
                    else
                    {
                        curveAnno = CreateCurveAnnotation(exporterIFC, curveElement, curveElement.Category.Id, sketchPlane.Id, curveLCS, curveStyle, setter, localPlacement, repItemHnd);
                        productWrapper.AddAnnotation(curveAnno, setter.LevelInfo, true);

                        annotationCache.AddAnnotation(sketchPlane.Id, curveStyle, curveAnno);
                    }
                }
                transaction.Commit();
            }
        }
Example #3
0
        /// <summary>
        /// Exports an element as an annotation.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="filledRegion">The filled region element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void Export(ExporterIFC exporterIFC, FilledRegion filledRegion,
                                  GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            if (filledRegion == null || geometryElement == null)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                IList <CurveLoop> boundaries = filledRegion.GetBoundaries();
                if (boundaries.Count == 0)
                {
                    return;
                }

                Plane plane = null;
                try
                {
                    plane = boundaries[0].GetPlane();
                }
                catch
                {
                    return;
                }

                Transform orientTrf = Transform.Identity;
                orientTrf.BasisX = plane.XVec; orientTrf.BasisY = plane.YVec; orientTrf.BasisZ = plane.Normal;
                orientTrf.Origin = plane.Origin;
                XYZ projectionDirection = plane.Normal;

                IList <IList <CurveLoop> > sortedLoops = ExporterIFCUtils.SortCurveLoops(boundaries);
                if (sortedLoops.Count == 0)
                {
                    return;
                }

                FilledRegionType filledRegionType = filledRegion.Document.GetElement(filledRegion.GetTypeId()) as FilledRegionType;
                Color            color            = filledRegionType != null ? filledRegionType.Color : new Color(0, 0, 0);
                ElementId        fillPatternId    = filledRegionType != null ? filledRegionType.FillPatternId : ElementId.InvalidElementId;
                ElementId        categoryId       = CategoryUtil.GetSafeCategoryId(filledRegion);

                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, filledRegion, null, orientTrf))
                {
                    foreach (IList <CurveLoop> curveLoopList in sortedLoops)
                    {
                        IFCAnyHandle           outerCurve  = null;
                        HashSet <IFCAnyHandle> innerCurves = null;
                        for (int ii = 0; ii < curveLoopList.Count; ii++)
                        {
                            IFCAnyHandle ifcCurve = GeometryUtil.CreateIFCCurveFromCurveLoop(exporterIFC, curveLoopList[ii], plane, projectionDirection);
                            if (ii == 0)
                            {
                                outerCurve = ifcCurve;
                            }
                            else
                            {
                                if (innerCurves == null)
                                {
                                    innerCurves = new HashSet <IFCAnyHandle>();
                                }
                                innerCurves.Add(ifcCurve);
                            }
                        }

                        IFCAnyHandle representItem = IFCInstanceExporter.CreateAnnotationFillArea(file, outerCurve, innerCurves);
                        file.CreateStyle(exporterIFC, representItem, color, fillPatternId);

                        HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>();
                        bodyItems.Add(representItem);
                        IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateAnnotationSetRep(exporterIFC, filledRegion, categoryId,
                                                                                            exporterIFC.Get2DContextHandle(), bodyItems);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd))
                        {
                            return;
                        }

                        List <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>();
                        shapeReps.Add(bodyRepHnd);

                        IFCAnyHandle productShape = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                        IFCAnyHandle annotation   = IFCInstanceExporter.CreateAnnotation(file, GUIDUtil.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                                                                         null, null, null, setter.LocalPlacement, productShape);

                        productWrapper.AddAnnotation(annotation, setter.LevelInfo, true);
                    }
                }

                transaction.Commit();
            }
        }
Example #4
0
        /// <summary>
        /// Exports a curve element to IFC curve annotation.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="curveElement">
        /// The curve element to be exported.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportCurveElement(ExporterIFC exporterIFC, CurveElement curveElement, GeometryElement geometryElement,
                                              IFCProductWrapper productWrapper)
        {
            if (geometryElement == null || !ShouldCurveElementBeExported(curveElement))
            {
                return;
            }

            SketchPlane sketchPlane = curveElement.SketchPlane;

            if (sketchPlane == null)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, curveElement))
                {
                    IFCAnyHandle localPlacement = setter.GetPlacement();
                    IFCAnyHandle axisPlacement  = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);

                    Plane planeSK      = sketchPlane.Plane;
                    XYZ   projDir      = planeSK.Normal;
                    XYZ   origin       = planeSK.Origin;
                    bool  useOffsetTrf = false;
                    if (projDir.IsAlmostEqualTo(XYZ.BasisZ))
                    {
                        XYZ offset = XYZ.BasisZ * setter.Offset;
                        origin -= offset;
                    }
                    else
                    {
                        useOffsetTrf = true;
                    }

                    Plane           plane = new Plane(planeSK.XVec, planeSK.YVec, origin);
                    IFCGeometryInfo info  = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, plane, projDir, false);

                    if (useOffsetTrf)
                    {
                        XYZ       offsetOrig = -XYZ.BasisZ * setter.Offset;
                        Transform trf        = Transform.get_Translation(offsetOrig);
                        ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false, trf);
                    }
                    else
                    {
                        ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false);
                    }

                    IList <IFCAnyHandle> curves = info.GetCurves();

                    if (curves.Count != 1)
                    {
                        throw new Exception("IFC: expected 1 curve when export curve element.");
                    }

                    HashSet <IFCAnyHandle> curveSet   = new HashSet <IFCAnyHandle>(curves);
                    IFCAnyHandle           repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(file, curveSet);

                    IFCAnyHandle curveStyle = file.CreateStyle(exporterIFC, repItemHnd);

                    CurveAnnotationCache annotationCache = ExporterCacheManager.CurveAnnotationCache;
                    IFCAnyHandle         curveAnno       = annotationCache.GetAnnotation(sketchPlane.Id, curveStyle);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveAnno))
                    {
                        AddCurvesToAnnotation(curveAnno, curves);
                    }
                    else
                    {
                        curveAnno = CreateCurveAnnotation(exporterIFC, curveElement, curveElement.Category.Id, sketchPlane.Id, plane, curveStyle, setter, localPlacement, repItemHnd);
                        productWrapper.AddAnnotation(curveAnno, setter.GetLevelInfo(), true);

                        annotationCache.AddAnnotation(sketchPlane.Id, curveStyle, curveAnno);
                    }
                }
                transaction.Commit();
            }
        }
Example #5
0
        /// <summary>
        /// Exports a curve element to IFC curve annotation.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="curveElement">
        /// The curve element to be exported.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void ExportCurveElement(ExporterIFC exporterIFC, CurveElement curveElement, GeometryElement geometryElement,
                                              ProductWrapper productWrapper)
        {
            if (geometryElement == null || !ShouldCurveElementBeExported(curveElement))
            {
                return;
            }

            SketchPlane sketchPlane = curveElement.SketchPlane;

            if (sketchPlane == null)
            {
                return;
            }

            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            Common.Enums.IFCEntityType elementClassTypeEnum;
            if (Enum.TryParse <Common.Enums.IFCEntityType>("IfcAnnotation", out elementClassTypeEnum))
            {
                if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                {
                    return;
                }
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, curveElement))
                {
                    IFCAnyHandle localPlacement = setter.LocalPlacement;
                    IFCAnyHandle axisPlacement  = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);

                    Plane planeSK      = sketchPlane.GetPlane();
                    XYZ   projDir      = planeSK.Normal;
                    XYZ   origin       = planeSK.Origin;
                    bool  useOffsetTrf = false;
                    if (projDir.IsAlmostEqualTo(XYZ.BasisZ))
                    {
                        XYZ offset = XYZ.BasisZ * setter.Offset;
                        origin -= offset;
                    }
                    else
                    {
                        useOffsetTrf = true;
                    }

                    Transform curveLCS = GeometryUtil.CreateTransformFromPlane(planeSK);
                    curveLCS.Origin = origin;
                    IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, curveLCS, projDir, false);

                    if (useOffsetTrf)
                    {
                        XYZ       offsetOrig = -XYZ.BasisZ * setter.Offset;
                        Transform trf        = Transform.CreateTranslation(offsetOrig);
                        ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false, trf);
                    }
                    else
                    {
                        ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false);
                    }

                    IList <IFCAnyHandle> curves = info.GetCurves();

                    if (curves.Count != 1)
                    {
                        throw new Exception("IFC: expected 1 curve when export curve element.");
                    }

                    HashSet <IFCAnyHandle> curveSet   = new HashSet <IFCAnyHandle>(curves);
                    IFCAnyHandle           repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(file, curveSet);

                    IFCAnyHandle curveStyle = file.CreateStyle(exporterIFC, repItemHnd);

                    CurveAnnotationCache annotationCache = ExporterCacheManager.CurveAnnotationCache;
                    IFCAnyHandle         curveAnno       = annotationCache.GetAnnotation(sketchPlane.Id, curveStyle);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveAnno))
                    {
                        AddCurvesToAnnotation(curveAnno, curves);
                    }
                    else
                    {
                        curveAnno = CreateCurveAnnotation(exporterIFC, curveElement, curveElement.Category.Id, sketchPlane.Id, curveLCS, curveStyle, setter, localPlacement, repItemHnd);
                        productWrapper.AddAnnotation(curveAnno, setter.LevelInfo, true);

                        annotationCache.AddAnnotation(sketchPlane.Id, curveStyle, curveAnno);
                    }
                }
                transaction.Commit();
            }
        }