Exemplo n.º 1
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;

                    IList <IFCAnyHandle> curves = null;

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

                        Curve curve = (geometryElement as GeometryObject) as Curve;

                        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);
                        curves = new List <IFCAnyHandle>();
                        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();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create the handle corresponding to the "Axis" IfcRepresentation for a beam, if possible.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC class.</param>
        /// <param name="element">The beam element.</param>
        /// <param name="catId">The beam category id.</param>
        /// <param name="axisInfo">The optional beam axis information.</param>
        /// <param name="offsetTransform">The optional offset transform applied to the "Body" representation.</param>
        /// <returns>The handle, or null if not created.</returns>
        private static IFCAnyHandle CreateBeamAxis(ExporterIFC exporterIFC, Element element, ElementId catId, BeamAxisInfo axisInfo, Transform offsetTransform)
        {
            if (axisInfo == null)
            {
                return(null);
            }

            Curve     curve   = axisInfo.Axis;
            XYZ       projDir = axisInfo.AxisNormal;
            Transform lcs     = axisInfo.LCSAsTransform;

            string representationTypeOpt = "Curve2D"; // This is by IFC2x2+ convention.

            XYZ curveOffset = XYZ.Zero;

            if (offsetTransform != null)
            {
                curveOffset = -UnitUtil.UnscaleLength(offsetTransform.Origin);
            }
            else
            {
                // Note that we do not have to have any scaling adjustment here, since the curve origin is in the
                // same internal coordinate system as the curve.
                curveOffset = -lcs.Origin;
            }

            Transform offsetLCS = new Transform(lcs);

            offsetLCS.Origin = XYZ.Zero;
            IList <IFCAnyHandle> axis_items = null;

            if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
            {
                IFCFile                 file         = exporterIFC.GetFile();
                IList <int>             segmentIndex = null;
                IList <IList <double> > pointList    = GeometryUtil.PointListFromCurve(exporterIFC, curve, null, 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 axisHnd      = IFCInstanceExporter.CreateIndexedPolyCurve(file, pointListHnd, segmentIndexList, false);
                axis_items = new List <IFCAnyHandle>();
                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(axisHnd))
                {
                    axis_items.Add(axisHnd);
                    representationTypeOpt = "Curve3D";   // We use Curve3D for IFC4RV Axis
                }
            }
            else
            {
                IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, offsetLCS, projDir, false);
                ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, curve, curveOffset, true);

                axis_items = info.GetCurves();
            }

            if (axis_items.Count > 0)
            {
                string       identifierOpt = "Axis"; // This is by IFC2x2+ convention.
                IFCAnyHandle axisRep       = RepresentationUtil.CreateShapeRepresentation(exporterIFC, element, catId, exporterIFC.Get3DContextHandle(identifierOpt),
                                                                                          identifierOpt, representationTypeOpt, axis_items);
                return(axisRep);
            }

            return(null);
        }