Esempio n. 1
0
        /// <summary>
        /// Checks if it is a door or window opening for a wall.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="openingElem">The opening element.</param>
        /// <param name="hostElement">The host element.</param>
        /// <returns>True if it is a door or window opening for a wall.</returns>
        public static bool IsDoorOrWindowOpening(ExporterIFC exporterIFC, Element openingElem, Element hostElement)
        {
            if (openingElem is FamilyInstance && hostElement is Wall)
            {
                string        ifcEnumType;
                IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, openingElem, out ifcEnumType);
                Element       instHost   = (openingElem as FamilyInstance).Host;
                return((exportType == IFCExportType.IfcDoorType || exportType == IFCExportType.IfcWindowType) &&
                       (instHost != null && instHost.Id == hostElement.Id));
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Exports a Group as an IfcGroup.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportGroupElement(ExporterIFC exporterIFC, Group element,
                                              ProductWrapper productWrapper)
        {
            if (element == null)
            {
                return(false);
            }

            // 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>("IfcGroup", out elementClassTypeEnum))
            {
                if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                {
                    return(false);
                }
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                IFCAnyHandle groupHnd = null;

                string       guid         = GUIDUtil.CreateGUID(element);
                IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
                string       name         = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                string       description  = NamingUtil.GetDescriptionOverride(element, null);
                string       objectType   = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());

                string            ifcEnumType;
                IFCExportInfoPair exportAs = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);
                if (exportAs.ExportInstance == IFCEntityType.IfcGroup)
                {
                    groupHnd = IFCInstanceExporter.CreateGroup(file, guid, ownerHistory, name, description, objectType);
                }

                if (groupHnd == null)
                {
                    return(false);
                }

                productWrapper.AddElement(element, groupHnd);

                ExporterCacheManager.GroupCache.RegisterGroup(element.Id, groupHnd);

                tr.Commit();
                return(true);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Export the roof to IfcRoof containing its parts.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The roof element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportRoofAsParts(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            string            ifcEnumType;
            IFCExportInfoPair exportType = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);

            if (exportType.IsUnKnown)
            {
                exportType = new IFCExportInfoPair(IFCEntityType.IfcRoof);
            }

            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(exportType.ExportType))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                // Check for containment override
                IFCAnyHandle overrideContainerHnd = null;
                ElementId    overrideContainerId  = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd);

                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd))
                {
                    IFCAnyHandle ownerHistory   = ExporterCacheManager.OwnerHistoryHandle;
                    IFCAnyHandle localPlacement = setter.LocalPlacement;

                    IFCAnyHandle prodRepHnd = null;

                    string elementGUID = GUIDUtil.CreateGUID(element);

                    IFCAnyHandle roofHandle = IFCInstanceExporter.CreateGenericIFCEntity(
                        exportType, exporterIFC,
                        element, elementGUID, ownerHistory,
                        localPlacement, prodRepHnd);

                    // Export the parts
                    PartExporter.ExportHostPart(exporterIFC, element, roofHandle, productWrapper, setter, localPlacement, null);

                    productWrapper.AddElement(element, roofHandle, setter, null, true, exportType);

                    transaction.Commit();
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Get the Default IFCExtrusionAxes for host element.
        /// Simply having roof/floor/wall/column as Z and everything else as XY.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="hostElement">The host element to get the IFCExtrusionAxes.</param>
        /// <returns>TryZ for wall/column/floor/roof elements and TryXY for other elements.</returns>
        private static IFCExtrusionAxes GetDefaultExtrusionAxesForHost(ExporterIFC exporterIFC, Element hostElement)
        {
            string        ifcEnumType;
            IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType);

            switch (exportType)
            {
            case IFCExportType.IfcWall:
            case IFCExportType.IfcColumnType:
            case IFCExportType.IfcSlab:
            case IFCExportType.IfcRoof:
                return(IFCExtrusionAxes.TryZ);

            default:
                return(IFCExtrusionAxes.TryXY);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Exports topography surface as IFC site object.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="topoSurface">The TopographySurface object.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportTopographySurface(ExporterIFC exporterIFC, TopographySurface topoSurface, GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            // Skip if the element is already processed and the Site has been created before
            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(ExporterCacheManager.SiteHandle) && !IFCAnyHandleUtil.IsNullOrHasNoValue(ExporterCacheManager.ElementToHandleCache.Find(topoSurface.Id)))
            {
                return;
            }

            string            ifcEnumType;
            IFCExportInfoPair exportType = ExporterUtil.GetExportType(exporterIFC, topoSurface, out ifcEnumType);

            // 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>(exportType.ExportInstance.ToString(), out elementClassTypeEnum) ||
                Enum.TryParse <Common.Enums.IFCEntityType>(exportType.ExportType.ToString(), out elementClassTypeEnum))
            {
                if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                {
                    return;
                }

                if (elementClassTypeEnum == Common.Enums.IFCEntityType.IfcSite)
                {
                    ExportSiteBase(exporterIFC, topoSurface.Document, topoSurface, geometryElement, productWrapper);
                }
                else
                {
                    // Export Default Site first before exporting the TopographySurface as a generic element
                    ExportDefaultSite(exporterIFC, topoSurface.Document, productWrapper);
                    using (ProductWrapper genElemProductWrapper = ProductWrapper.Create(exporterIFC, true))
                    {
                        GenericElementExporter.ExportGenericElement(exporterIFC, topoSurface, geometryElement, genElemProductWrapper, exportType);
                        ExporterUtil.ExportRelatedProperties(exporterIFC, topoSurface, genElemProductWrapper);
                    }
                    productWrapper.ClearInternalHandleWrapperData(topoSurface.Document.ProjectInformation);
                }
            }
            else
            {
                ExportSiteBase(exporterIFC, null, topoSurface, geometryElement, productWrapper);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Exports a Group as an IfcGroup.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportGroupElement(ExporterIFC exporterIFC, Group element,
                                              ProductWrapper productWrapper)
        {
            if (element == null)
            {
                return(false);
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                IFCAnyHandle groupHnd = null;

                string       guid         = GUIDUtil.CreateGUID(element);
                IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
                string       name         = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                string       description  = NamingUtil.GetDescriptionOverride(element, null);
                string       objectType   = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());

                string        ifcEnumType;
                IFCExportType exportAs = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);
                if (exportAs == IFCExportType.IfcGroup)
                {
                    groupHnd = IFCInstanceExporter.CreateGroup(file, guid, ownerHistory, name, description, objectType);
                }

                if (groupHnd == null)
                {
                    return(false);
                }

                productWrapper.AddElement(element, groupHnd);

                ExporterCacheManager.GroupCache.RegisterGroup(element.Id, groupHnd);

                tr.Commit();
                return(true);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Exports a ramp to IfcRamp.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The ramp element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void Export(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            string ifcEnumType = null;

            ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                StairsExporter.ExportLegacyStairOrRampAsContainer(exporterIFC, ifcEnumType, element, geometryElement, productWrapper);

                // If we didn't create a handle here, then the element wasn't a "native" Ramp, and is likely a FamilyInstance or a DirectShape.
                if (IFCAnyHandleUtil.IsNullOrHasNoValue(productWrapper.GetAnElement()))
                {
                    int numFlights = GetNumFlightsForRamp(exporterIFC, element);
                    if (numFlights > 0)
                    {
                        ExportRamp(exporterIFC, ifcEnumType, element, geometryElement, numFlights, productWrapper);
                    }
                }

                tr.Commit();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Exports a roof to IfcRoof.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="roof">The roof element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportRoof(ExporterIFC exporterIFC, Element roof, GeometryElement geometryElement,
                                      ProductWrapper productWrapper)
        {
            if (roof == null || geometryElement == null)
            {
                return;
            }

            string            ifcEnumType;
            IFCExportInfoPair roofExportType = ExporterUtil.GetExportType(exporterIFC, roof, out ifcEnumType);

            if (roofExportType.IsUnKnown)
            {
                roofExportType = new IFCExportInfoPair(IFCEntityType.IfcRoof, "");
            }

            MaterialLayerSetInfo layersetInfo = null;
            IFCFile  file = exporterIFC.GetFile();
            Document doc  = roof.Document;

            using (SubTransaction tempPartTransaction = new SubTransaction(doc))
            {
                // For IFC4RV export, Roof will be split into its parts(temporarily) in order to export the roof by its parts
                bool exportByComponents = ExporterUtil.ShouldExportByComponents(roof);

                using (IFCTransaction tr = new IFCTransaction(file))
                {
                    // Check for containment override
                    IFCAnyHandle overrideContainerHnd = null;
                    ElementId    overrideContainerId  = ParameterUtil.OverrideContainmentParameter(exporterIFC, roof, out overrideContainerHnd);

                    using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, roof, null, null, overrideContainerId, overrideContainerHnd))
                    {
                        using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                        {
                            // If the roof is an in-place family, we will allow any arbitrary orientation.  While this may result in some
                            // in-place "cubes" exporting with the wrong direction, it is unlikely that an in-place family would be
                            // used for this reason in the first place.
                            ecData.PossibleExtrusionAxes   = (roof is FamilyInstance) ? IFCExtrusionAxes.TryXYZ : IFCExtrusionAxes.TryZ;
                            ecData.AreInnerRegionsOpenings = true;
                            ecData.SetLocalPlacement(placementSetter.LocalPlacement);

                            ElementId categoryId = CategoryUtil.GetSafeCategoryId(roof);

                            BodyExporterOptions  bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow);
                            BodyData             bodyData            = null;
                            IFCAnyHandle         prodRep             = null;
                            IList <IFCAnyHandle> representations     = new List <IFCAnyHandle>();
                            IList <ElementId>    materialIds         = new List <ElementId>();

                            if (!exportByComponents)
                            {
                                prodRep = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC, roof,
                                                                                                     categoryId, geometryElement, bodyExporterOptions, null, ecData, out bodyData);
                                if (bodyData != null && bodyData.MaterialIds != null)
                                {
                                    materialIds = bodyData.MaterialIds;
                                }
                            }
                            else
                            {
                                prodRep = RepresentationUtil.CreateProductDefinitionShapeWithoutBodyRep(exporterIFC, roof, categoryId, geometryElement, representations);
                            }
                            if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodRep))
                            {
                                ecData.ClearOpenings();
                                return;
                            }

                            bool exportSlab = ((ecData.ScaledLength > MathUtil.Eps() || exportByComponents) &&
                                               roofExportType.ExportInstance == IFCEntityType.IfcRoof);

                            string       guid           = GUIDUtil.CreateGUID(roof);
                            IFCAnyHandle ownerHistory   = ExporterCacheManager.OwnerHistoryHandle;
                            IFCAnyHandle localPlacement = ecData.GetLocalPlacement();

                            IFCAnyHandle roofHnd = IFCInstanceExporter.CreateGenericIFCEntity(
                                roofExportType, exporterIFC, roof, guid, ownerHistory,
                                localPlacement, exportSlab ? null : prodRep);

                            IFCAnyHandle typeHnd = ExporterUtil.CreateGenericTypeFromElement(roof,
                                                                                             roofExportType, file, ownerHistory, roofExportType.ValidatedPredefinedType,
                                                                                             productWrapper);
                            ExporterCacheManager.TypeRelationsCache.Add(typeHnd, roofHnd);

                            productWrapper.AddElement(roof, roofHnd, placementSetter.LevelInfo, ecData, true, roofExportType);

                            if (exportSlab)
                            {
                                string       slabGUID = GUIDUtil.CreateSubElementGUID(roof, (int)IFCRoofSubElements.RoofSlabStart);
                                string       slabName = IFCAnyHandleUtil.GetStringAttribute(roofHnd, "Name") + ":1";
                                IFCAnyHandle slabLocalPlacementHnd = ExporterUtil.CopyLocalPlacement(file, localPlacement);

                                if (exportByComponents)
                                {
                                    IFCAnyHandle hostShapeRepFromParts = PartExporter.ExportHostPartAsShapeAspects(exporterIFC, roof, prodRep,
                                                                                                                   productWrapper, placementSetter, localPlacement, ElementId.InvalidElementId, out layersetInfo, ecData);
                                    if (layersetInfo != null && layersetInfo.MaterialIds != null)
                                    {
                                        materialIds = layersetInfo.MaterialIds.Select(x => x.Item1).ToList();
                                    }
                                }

                                IFCAnyHandle slabHnd = IFCInstanceExporter.CreateSlab(exporterIFC, roof, slabGUID, ownerHistory,
                                                                                      slabLocalPlacementHnd, prodRep, slabRoofPredefinedType);
                                IFCAnyHandleUtil.OverrideNameAttribute(slabHnd, slabName);

                                Transform offsetTransform = (bodyData != null) ? bodyData.OffsetTransform : Transform.Identity;
                                OpeningUtil.CreateOpeningsIfNecessary(slabHnd, roof, ecData, offsetTransform,
                                                                      exporterIFC, slabLocalPlacementHnd, placementSetter, productWrapper);

                                ExporterUtil.RelateObject(exporterIFC, roofHnd, slabHnd);
                                IFCExportInfoPair slabRoofExportType = new IFCExportInfoPair(IFCEntityType.IfcSlab, slabRoofPredefinedType);

                                productWrapper.AddElement(null, slabHnd, placementSetter.LevelInfo, ecData, false, slabRoofExportType);

                                // Create type

                                IFCAnyHandle slabRoofTypeHnd = ExporterUtil.CreateGenericTypeFromElement(roof, slabRoofExportType, exporterIFC.GetFile(), ownerHistory, slabRoofPredefinedType, productWrapper);
                                ExporterCacheManager.TypeRelationsCache.Add(slabRoofTypeHnd, slabHnd);

                                if (!ExporterUtil.AddIntoComplexPropertyCache(slabHnd, layersetInfo) && bodyData != null)
                                {
                                    CategoryUtil.CreateMaterialAssociation(exporterIFC, slabHnd, bodyData.MaterialIds);
                                }

                                // Create material association here
                                if (layersetInfo != null && !IFCAnyHandleUtil.IsNullOrHasNoValue(layersetInfo.MaterialLayerSetHandle))
                                {
                                    CategoryUtil.CreateMaterialAssociation(exporterIFC, slabHnd, layersetInfo.MaterialLayerSetHandle);
                                }
                                else if (!(roof is RoofBase))
                                {
                                    CategoryUtil.CreateMaterialAssociation(exporterIFC, roofHnd, materialIds);
                                }
                            }
                        }
                        tr.Commit();
                    }
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Export the individual part (IfcBuildingElementPart).
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="partElement">The part element to export.</param>
        /// <param name="geometryElement">The geometry of part.</param>
        /// <param name="productWrapper">The ProductWrapper object.</param>
        /// <param name="placementSetter"></param>
        /// <param name="originalPlacement"></param>
        /// <param name="range"></param>
        /// <param name="ifcExtrusionAxes"></param>
        /// <param name="hostElement">The host of the part.  This can be null.</param>
        /// <param name="overrideLevelId">The id of the level that the part is one, overridding other sources.</param>
        /// <param name="asBuildingElement">If true, export the Part as a building element instead of an IfcElementPart.</param>
        public static void ExportPart(ExporterIFC exporterIFC, Element partElement, ProductWrapper productWrapper,
                                      PlacementSetter placementSetter, IFCAnyHandle originalPlacement, IFCRange range, IFCExtrusionAxes ifcExtrusionAxes,
                                      Element hostElement, ElementId overrideLevelId, bool asBuildingElement)
        {
            if (!ElementFilteringUtil.IsElementVisible(partElement))
            {
                return;
            }

            Part part = partElement as Part;

            if (part == null)
            {
                return;
            }

            // We don't know how to export a part as a building element if we don't know it's host.
            if (asBuildingElement && (hostElement == null))
            {
                return;
            }

            if (!asBuildingElement)
            {
                // Check the intended IFC entity or type name is in the exclude list specified in the UI
                Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcBuildingElementPart;
                if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                {
                    return;
                }
            }
            else
            {
                string            ifcEnumType = null;
                IFCExportInfoPair exportType  = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType);

                // 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>(exportType.ToString(), out elementClassTypeEnum))
                {
                    if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                    {
                        return;
                    }
                }
            }

            PlacementSetter standalonePlacementSetter = null;
            bool            standaloneExport          = hostElement == null || asBuildingElement;

            ElementId partExportLevelId = (overrideLevelId != null) ? overrideLevelId : null;

            if (partExportLevelId == null && standaloneExport)
            {
                partExportLevelId = partElement.LevelId;
            }

            if (partExportLevelId == null)
            {
                if (hostElement == null || (part.OriginalCategoryId != hostElement.Category.Id))
                {
                    return;
                }
                partExportLevelId = hostElement.LevelId;
            }

            if (ExporterCacheManager.PartExportedCache.HasExported(partElement.Id, partExportLevelId))
            {
                return;
            }

            Options options   = GeometryUtil.GetIFCExportGeometryOptions();
            View    ownerView = partElement.Document.GetElement(partElement.OwnerViewId) as View;

            if (ownerView != null)
            {
                options.View = ownerView;
            }

            GeometryElement geometryElement = partElement.get_Geometry(options);

            if (geometryElement == null)
            {
                return;
            }

            try
            {
                IFCFile file = exporterIFC.GetFile();
                using (IFCTransaction transaction = new IFCTransaction(file))
                {
                    IFCAnyHandle partPlacement = null;
                    if (standaloneExport)
                    {
                        Transform    orientationTrf       = Transform.Identity;
                        IFCAnyHandle overrideContainerHnd = null;
                        ElementId    overrideContainerId  = ParameterUtil.OverrideContainmentParameter(exporterIFC, partElement, out overrideContainerHnd);
                        if (overrideContainerId != ElementId.InvalidElementId && (partExportLevelId == null || partExportLevelId == ElementId.InvalidElementId))
                        {
                            partExportLevelId = overrideContainerId;
                        }

                        standalonePlacementSetter = PlacementSetter.Create(exporterIFC, partElement, null, orientationTrf, partExportLevelId, overrideContainerHnd);
                        partPlacement             = standalonePlacementSetter.LocalPlacement;
                    }
                    else
                    {
                        //partPlacement = ExporterUtil.CreateLocalPlacement(file, null, null);
                        partPlacement = ExporterUtil.CreateLocalPlacement(file, originalPlacement, null);
                    }

                    bool validRange = (range != null && !MathUtil.IsAlmostZero(range.Start - range.End));

                    SolidMeshGeometryInfo solidMeshInfo;
                    if (validRange)
                    {
                        solidMeshInfo = GeometryUtil.GetSplitClippedSolidMeshGeometry(geometryElement, range);
                        if (solidMeshInfo.GetSolids().Count == 0 && solidMeshInfo.GetMeshes().Count == 0)
                        {
                            return;
                        }
                    }
                    else
                    {
                        solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement);
                    }

                    using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData())
                    {
                        extrusionCreationData.SetLocalPlacement(partPlacement);
                        extrusionCreationData.ReuseLocalPlacement   = false;
                        extrusionCreationData.PossibleExtrusionAxes = ifcExtrusionAxes;

                        IList <Solid>          solids = new List <Solid>();;
                        IList <Mesh>           meshes = new List <Mesh>();
                        IList <GeometryObject> gObjs  = FamilyExporterUtil.RemoveInvisibleSolidsAndMeshes(partElement.Document, exporterIFC, solidMeshInfo.GetSolids(), solidMeshInfo.GetMeshes());
                        foreach (GeometryObject gObj in gObjs)
                        {
                            if (gObj is Solid)
                            {
                                solids.Add(gObj as Solid);
                            }
                            else if (gObj is Mesh)
                            {
                                meshes.Add(gObj as Mesh);
                            }
                        }

                        ElementId catId     = CategoryUtil.GetSafeCategoryId(partElement);
                        ElementId hostCatId = CategoryUtil.GetSafeCategoryId(hostElement);

                        BodyData            bodyData            = null;
                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow);
                        if (solids.Count > 0 || meshes.Count > 0)
                        {
                            bodyData = BodyExporter.ExportBody(exporterIFC, partElement, catId, ElementId.InvalidElementId, solids, meshes,
                                                               bodyExporterOptions, extrusionCreationData);
                        }
                        else
                        {
                            IList <GeometryObject> geomlist = new List <GeometryObject>();
                            geomlist.Add(geometryElement);
                            bodyData = BodyExporter.ExportBody(exporterIFC, partElement, catId, ElementId.InvalidElementId, geomlist,
                                                               bodyExporterOptions, extrusionCreationData);
                        }

                        IFCAnyHandle bodyRep = bodyData.RepresentationHnd;
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep))
                        {
                            extrusionCreationData.ClearOpenings();
                            return;
                        }

                        IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();
                        representations.Add(bodyRep);

                        IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geometryElement, Transform.Identity);
                        if (boundingBoxRep != null)
                        {
                            representations.Add(boundingBoxRep);
                        }

                        IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);

                        IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;

                        string            partGUID    = GUIDUtil.CreateGUID(partElement);
                        string            ifcEnumType = null;
                        IFCExportInfoPair exportType  = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType);
                        IFCAnyHandle      ifcPart     = null;
                        if (!asBuildingElement)
                        {
                            ifcPart = IFCInstanceExporter.CreateBuildingElementPart(exporterIFC, partElement, partGUID, ownerHistory,
                                                                                    extrusionCreationData.GetLocalPlacement(), prodRep);
                        }
                        else
                        {
                            switch (exportType.ExportInstance)
                            {
                            case IFCEntityType.IfcColumn:
                                ifcPart = IFCInstanceExporter.CreateColumn(exporterIFC, partElement, partGUID, ownerHistory,
                                                                           extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType);
                                break;

                            case IFCEntityType.IfcCovering:
                                ifcPart = IFCInstanceExporter.CreateCovering(exporterIFC, partElement, partGUID, ownerHistory,
                                                                             extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType);
                                break;

                            case IFCEntityType.IfcFooting:
                                ifcPart = IFCInstanceExporter.CreateFooting(exporterIFC, partElement, partGUID, ownerHistory,
                                                                            extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType);
                                break;

                            case IFCEntityType.IfcPile:
                                ifcPart = IFCInstanceExporter.CreatePile(exporterIFC, partElement, partGUID, ownerHistory,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType, null);
                                break;

                            case IFCEntityType.IfcRoof:
                                ifcPart = IFCInstanceExporter.CreateRoof(exporterIFC, partElement, partGUID, ownerHistory,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType);
                                break;

                            case IFCEntityType.IfcSlab:
                            {
                                // TODO: fix this elsewhere.
                                if (ExporterUtil.IsNotDefined(ifcEnumType))
                                {
                                    if (hostCatId == new ElementId(BuiltInCategory.OST_Floors))
                                    {
                                        ifcEnumType = "FLOOR";
                                    }
                                    else if (hostCatId == new ElementId(BuiltInCategory.OST_Roofs))
                                    {
                                        ifcEnumType = "ROOF";
                                    }
                                }

                                ifcPart = IFCInstanceExporter.CreateSlab(exporterIFC, partElement, partGUID, ownerHistory,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType);
                            }
                            break;

                            case IFCEntityType.IfcWall:
                                ifcPart = IFCInstanceExporter.CreateWall(exporterIFC, partElement, partGUID, ownerHistory,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType);
                                break;

                            default:
                                ifcPart = IFCInstanceExporter.CreateBuildingElementProxy(exporterIFC, partElement, partGUID, ownerHistory,
                                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, exportType.ValidatedPredefinedType);
                                break;
                            }
                        }

                        bool            containedInLevel     = standaloneExport;
                        PlacementSetter whichPlacementSetter = containedInLevel ? standalonePlacementSetter : placementSetter;
                        productWrapper.AddElement(partElement, ifcPart, whichPlacementSetter, extrusionCreationData, containedInLevel, exportType);

                        OpeningUtil.CreateOpeningsIfNecessary(ifcPart, partElement, extrusionCreationData, bodyData.OffsetTransform, exporterIFC,
                                                              extrusionCreationData.GetLocalPlacement(), whichPlacementSetter, productWrapper);

                        //Add the exported part to exported cache.
                        TraceExportedParts(partElement, partExportLevelId, standaloneExport ? ElementId.InvalidElementId : hostElement.Id);

                        CategoryUtil.CreateMaterialAssociation(exporterIFC, ifcPart, bodyData.MaterialIds);

                        transaction.Commit();
                    }
                }
            }
            finally
            {
                if (standalonePlacementSetter != null)
                {
                    standalonePlacementSetter.Dispose();
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Exports a floor to IFC slab.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="floor">
        /// The floor element.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="ifcEnumType">
        /// The string value represents the IFC type.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        /// <param name="exportParts">
        /// Whether to export parts or not.
        /// </param>
        /// <returns>
        /// True if the floor is exported successfully, false otherwise.
        /// </returns>
        public static void ExportFloor(ExporterIFC exporterIFC, Element floorElement, GeometryElement geometryElement, string ifcEnumType,
                                       ProductWrapper productWrapper, bool exportParts)
        {
            if (geometryElement == null)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();
            IList <IFCAnyHandle> slabHnds        = new List <IFCAnyHandle>();
            IList <IFCAnyHandle> brepSlabHnds    = new List <IFCAnyHandle>();
            IList <IFCAnyHandle> nonBrepSlabHnds = new List <IFCAnyHandle>();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCTransformSetter transformSetter = IFCTransformSetter.Create())
                {
                    using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, floorElement, null, null, ExporterUtil.GetBaseLevelIdForElement(floorElement)))
                    {
                        IFCAnyHandle localPlacement = placementSetter.GetPlacement();
                        IFCAnyHandle ownerHistory   = exporterIFC.GetOwnerHistoryHandle();
                        bool         exportedAsInternalExtrusion = false;

                        double    scale = exporterIFC.LinearScale;
                        ElementId catId = CategoryUtil.GetSafeCategoryId(floorElement);

                        IList <IFCAnyHandle>             prodReps        = new List <IFCAnyHandle>();
                        IList <ShapeRepresentationType>  repTypes        = new List <ShapeRepresentationType>();
                        IList <IList <CurveLoop> >       extrusionLoops  = new List <IList <CurveLoop> >();
                        IList <IFCExtrusionCreationData> loopExtraParams = new List <IFCExtrusionCreationData>();
                        Plane floorPlane = GeometryUtil.CreateDefaultPlane();

                        IList <IFCAnyHandle> localPlacements = new List <IFCAnyHandle>();

                        if (!exportParts)
                        {
                            // First, try to use the ExtrusionAnalyzer for the limited cases it handles - 1 solid, no openings, end clippings only.
                            // Also limited to cases with line and arc boundaries.
                            //
                            if (floorElement is Floor)
                            {
                                Floor floor = floorElement as Floor;
                                SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement);
                                IList <Solid>         solids        = solidMeshInfo.GetSolids();
                                IList <Mesh>          meshes        = solidMeshInfo.GetMeshes();

                                if (solids.Count == 1 && meshes.Count == 0)
                                {
                                    bool completelyClipped;
                                    XYZ  floorExtrusionDirection = new XYZ(0, 0, -1);
                                    XYZ  modelOrigin             = XYZ.Zero;

                                    XYZ floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                                    if (floorOrigin == null)
                                    {
                                        // GetVerticalProjectionPoint may return null if FloorFace.Top is an edited face that doesn't
                                        // go thruough te Revit model orgigin.  We'll try the midpoint of the bounding box instead.
                                        BoundingBoxXYZ boundingBox = floor.get_BoundingBox(null);
                                        modelOrigin = (boundingBox.Min + boundingBox.Max) / 2.0;
                                        floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                                    }

                                    if (floorOrigin != null)
                                    {
                                        XYZ   floorDir = floor.GetNormalAtVerticalProjectionPoint(floorOrigin, FloorFace.Top);
                                        Plane extrusionAnalyzerFloorPlane = new Plane(floorDir, floorOrigin);

                                        HandleAndData floorAndProperties =
                                            ExtrusionExporter.CreateExtrusionWithClippingAndProperties(exporterIFC, floor,
                                                                                                       catId, solids[0], extrusionAnalyzerFloorPlane, floorExtrusionDirection, null, out completelyClipped);
                                        if (completelyClipped)
                                        {
                                            return;
                                        }
                                        if (floorAndProperties.Handle != null)
                                        {
                                            IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();
                                            representations.Add(floorAndProperties.Handle);
                                            IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);
                                            prodReps.Add(prodRep);
                                            repTypes.Add(ShapeRepresentationType.SweptSolid);

                                            if (floorAndProperties.Data != null)
                                            {
                                                loopExtraParams.Add(floorAndProperties.Data);
                                            }
                                        }
                                    }
                                }
                            }


                            // Use internal routine as backup that handles openings.
                            if (prodReps.Count == 0)
                            {
                                exportedAsInternalExtrusion = ExporterIFCUtils.ExportSlabAsExtrusion(exporterIFC, floorElement,
                                                                                                     geometryElement, transformSetter, localPlacement, out localPlacements, out prodReps,
                                                                                                     out extrusionLoops, out loopExtraParams, floorPlane);
                                for (int ii = 0; ii < prodReps.Count; ii++)
                                {
                                    // all are extrusions
                                    repTypes.Add(ShapeRepresentationType.SweptSolid);
                                }
                            }

                            if (prodReps.Count == 0)
                            {
                                using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                                {
                                    BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                                    bodyExporterOptions.TessellationLevel = BodyExporter.GetTessellationLevel();
                                    BodyData     bodyData;
                                    IFCAnyHandle prodDefHnd = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC,
                                                                                                                         floorElement, catId, geometryElement, bodyExporterOptions, null, ecData, out bodyData);
                                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodDefHnd))
                                    {
                                        ecData.ClearOpenings();
                                        return;
                                    }

                                    prodReps.Add(prodDefHnd);
                                    repTypes.Add(bodyData.ShapeRepresentationType);
                                }
                            }
                        }

                        // Create the slab from either the extrusion or the BRep information.
                        string ifcGUID = GUIDUtil.CreateGUID(floorElement);

                        int numReps = exportParts ? 1 : prodReps.Count;

                        // Allow export as IfcSlab or IfcFooting.  Ignore altIfcEnumType value; use value passed in.
                        string        altIfcEnumType;
                        IFCExportType exportAs        = ExporterUtil.GetExportType(exporterIFC, floorElement, out altIfcEnumType);
                        bool          exportAsFooting = (exportAs == IFCExportType.ExportFooting);

                        IFCFootingType?footingType = null;
                        IFCSlabType?   slabType    = null;
                        if (exportAsFooting)
                        {
                            footingType = FootingExporter.GetIFCFootingType(ifcEnumType);
                        }
                        else
                        {
                            slabType = GetIFCSlabType(ifcEnumType);
                        }

                        for (int ii = 0; ii < numReps; ii++)
                        {
                            string ifcName        = NamingUtil.GetNameOverride(floorElement, NamingUtil.GetIFCNamePlusIndex(floorElement, ii == 0 ? -1 : ii + 1));
                            string ifcDescription = NamingUtil.GetDescriptionOverride(floorElement, null);
                            string ifcObjectType  = NamingUtil.GetObjectTypeOverride(floorElement, exporterIFC.GetFamilyName());
                            string ifcTag         = NamingUtil.GetTagOverride(floorElement, NamingUtil.CreateIFCElementId(floorElement));

                            string       currentGUID       = (ii == 0) ? ifcGUID : GUIDUtil.CreateGUID();
                            IFCAnyHandle localPlacementHnd = exportedAsInternalExtrusion ? localPlacements[ii] : localPlacement;

                            IFCAnyHandle slabHnd = null;
                            if (exportAsFooting)
                            {
                                slabHnd = IFCInstanceExporter.CreateFooting(file, currentGUID, ownerHistory, ifcName,
                                                                            ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                            ifcTag, footingType.Value);
                            }
                            else
                            {
                                slabHnd = IFCInstanceExporter.CreateSlab(file, currentGUID, ownerHistory, ifcName,
                                                                         ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                         ifcTag, slabType.Value);
                            }

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

                            if (exportParts)
                            {
                                PartExporter.ExportHostPart(exporterIFC, floorElement, slabHnd, productWrapper, placementSetter, localPlacementHnd, null);
                            }

                            slabHnds.Add(slabHnd);

                            if (!exportParts)
                            {
                                if (repTypes[ii] == ShapeRepresentationType.Brep)
                                {
                                    brepSlabHnds.Add(slabHnd);
                                }
                                else
                                {
                                    nonBrepSlabHnds.Add(slabHnd);
                                }
                            }
                        }

                        for (int ii = 0; ii < numReps; ii++)
                        {
                            IFCExtrusionCreationData loopExtraParam = ii < loopExtraParams.Count ? loopExtraParams[ii] : null;
                            productWrapper.AddElement(floorElement, slabHnds[ii], placementSetter, loopExtraParam, true);
                        }

                        if (exportedAsInternalExtrusion)
                        {
                            ExporterIFCUtils.ExportExtrudedSlabOpenings(exporterIFC, floorElement, placementSetter,
                                                                        localPlacements[0], slabHnds, extrusionLoops, floorPlane, productWrapper.ToNative());
                        }
                    }

                    if (!exportParts)
                    {
                        if (floorElement is HostObject)
                        {
                            HostObject hostObject = floorElement as HostObject;
                            if (nonBrepSlabHnds.Count > 0)
                            {
                                HostObjectExporter.ExportHostObjectMaterials(exporterIFC, hostObject, nonBrepSlabHnds,
                                                                             geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, false);
                            }
                            if (brepSlabHnds.Count > 0)
                            {
                                HostObjectExporter.ExportHostObjectMaterials(exporterIFC, hostObject, brepSlabHnds,
                                                                             geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, true);
                            }
                        }
                        else if (floorElement is FamilyInstance && slabHnds.Count > 0)
                        {
                            ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, exporterIFC, floorElement);
                            Document  doc   = floorElement.Document;
                            foreach (IFCAnyHandle slabHnd in slabHnds)
                            {
                                CategoryUtil.CreateMaterialAssociation(exporterIFC, slabHnd, matId);
                            }
                        }
                    }
                }
                tr.Commit();

                return;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Exports an element as IFC railing.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="element">
        /// The element to be exported.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void ExportRailing(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, string ifcEnumType, ProductWrapper productWrapper)
        {
            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcRailing;
            if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
            {
                return;
            }

            ElementType elemType    = element.Document.GetElement(element.GetTypeId()) as ElementType;
            IFCFile     file        = exporterIFC.GetFile();
            Options     geomOptions = GeometryUtil.GetIFCExportGeometryOptions();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                // Check for containment override
                IFCAnyHandle overrideContainerHnd = null;
                ElementId    overrideContainerId  = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd);

                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        IFCAnyHandle           localPlacement = setter.LocalPlacement;
                        StairRampContainerInfo stairRampInfo  = null;
                        ElementId hostId     = GetStairOrRampHostId(exporterIFC, element as Railing);
                        Transform inverseTrf = Transform.Identity;
                        if (hostId != ElementId.InvalidElementId)
                        {
                            stairRampInfo = ExporterCacheManager.StairRampContainerInfoCache.GetStairRampContainerInfo(hostId);
                            IFCAnyHandle stairRampLocalPlacement = stairRampInfo.LocalPlacements[0];
                            Transform    relTrf = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(stairRampLocalPlacement, localPlacement);
                            inverseTrf = relTrf.Inverse;

                            IFCAnyHandle railingLocalPlacement = ExporterUtil.CreateLocalPlacement(file, stairRampLocalPlacement,
                                                                                                   inverseTrf.Origin, inverseTrf.BasisZ, inverseTrf.BasisX);
                            localPlacement = railingLocalPlacement;
                        }
                        ecData.SetLocalPlacement(localPlacement);

                        SolidMeshGeometryInfo  solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geomElem);
                        IList <Solid>          solids        = solidMeshInfo.GetSolids();
                        IList <Mesh>           meshes        = solidMeshInfo.GetMeshes();
                        IList <GeometryObject> gObjs         = FamilyExporterUtil.RemoveInvisibleSolidsAndMeshes(element.Document, exporterIFC, ref solids, ref meshes);

                        Railing           railingElem   = element as Railing;
                        IList <ElementId> subElementIds = CollectSubElements(railingElem);

                        foreach (ElementId subElementId in subElementIds)
                        {
                            Element subElement = railingElem.Document.GetElement(subElementId);
                            if (subElement != null)
                            {
                                GeometryElement subElementGeom = GeometryUtil.GetOneLevelGeometryElement(subElement.get_Geometry(geomOptions), 0);

                                SolidMeshGeometryInfo  subElementSolidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(subElementGeom);
                                IList <Solid>          subElemSolids           = subElementSolidMeshInfo.GetSolids();
                                IList <Mesh>           subElemMeshes           = subElementSolidMeshInfo.GetMeshes();
                                IList <GeometryObject> partGObjs = FamilyExporterUtil.RemoveInvisibleSolidsAndMeshes(element.Document, exporterIFC, ref subElemSolids, ref subElemMeshes);
                                foreach (Solid subElSolid in subElemSolids)
                                {
                                    solids.Add(subElSolid);
                                }
                                foreach (Mesh subElMesh in subElemMeshes)
                                {
                                    meshes.Add(subElMesh);
                                }
                            }
                        }

                        ElementId           catId               = CategoryUtil.GetSafeCategoryId(element);
                        BodyData            bodyData            = null;
                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.Medium);

                        if (solids.Count > 0 || meshes.Count > 0)
                        {
                            bodyData = BodyExporter.ExportBody(exporterIFC, element, catId, ElementId.InvalidElementId, solids, meshes, bodyExporterOptions, ecData);
                        }
                        else
                        {
                            IList <GeometryObject> geomlist = new List <GeometryObject>();
                            geomlist.Add(geomElem);
                            bodyData = BodyExporter.ExportBody(exporterIFC, element, catId, ElementId.InvalidElementId, geomlist, bodyExporterOptions, ecData);
                        }

                        IFCAnyHandle bodyRep = bodyData.RepresentationHnd;
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep))
                        {
                            if (ecData != null)
                            {
                                ecData.ClearOpenings();
                            }
                            return;
                        }

                        IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();
                        representations.Add(bodyRep);

                        IList <GeometryObject> geomObjects = new List <GeometryObject>(solids);
                        foreach (Mesh mesh in meshes)
                        {
                            geomObjects.Add(mesh);
                        }

                        Transform boundingBoxTrf = (bodyData.OffsetTransform != null) ? bodyData.OffsetTransform.Inverse : Transform.Identity;
                        boundingBoxTrf = inverseTrf.Multiply(boundingBoxTrf);
                        IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geomObjects, boundingBoxTrf);
                        if (boundingBoxRep != null)
                        {
                            representations.Add(boundingBoxRep);
                        }

                        IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);

                        IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;

                        string instanceGUID = GUIDUtil.CreateGUID(element);

                        IFCExportInfoPair exportInfo = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);

                        IFCAnyHandle railing = IFCInstanceExporter.CreateGenericIFCEntity(exportInfo, exporterIFC, element, instanceGUID, ownerHistory,
                                                                                          ecData.GetLocalPlacement(), prodRep);

                        bool associateToLevel = (hostId == ElementId.InvalidElementId);

                        productWrapper.AddElement(element, railing, setter, ecData, associateToLevel, exportInfo);
                        OpeningUtil.CreateOpeningsIfNecessary(railing, element, ecData, bodyData.OffsetTransform,
                                                              exporterIFC, ecData.GetLocalPlacement(), setter, productWrapper);

                        IFCAnyHandle      singleMaterialOverrideHnd = null;
                        IList <ElementId> matIds       = null;
                        ElementId         defaultMatId = ElementId.InvalidElementId;
                        ElementId         matId        = CategoryUtil.GetBaseMaterialIdForElement(element);

                        // Get IfcSingleMaterialOverride to work for railing
                        singleMaterialOverrideHnd = ExporterUtil.GetSingleMaterial(exporterIFC, element, matId);
                        if (singleMaterialOverrideHnd != null)
                        {
                            matIds = new List <ElementId> {
                                matId
                            };
                        }
                        else
                        {
                            matIds       = bodyData.MaterialIds;
                            defaultMatId = matIds[0];

                            // Check if all the items are the same, then get the first material id
                            if (matIds.All(x => x == defaultMatId))
                            {
                                matIds = new List <ElementId> {
                                    defaultMatId
                                };
                            }
                        }

                        CategoryUtil.CreateMaterialAssociationWithShapeAspect(exporterIFC, element, railing, bodyData.RepresentationItemInfo);

                        // Create multi-story duplicates of this railing.
                        if (stairRampInfo != null)
                        {
                            stairRampInfo.AddComponent(0, railing);

                            List <IFCAnyHandle> stairHandles = stairRampInfo.StairOrRampHandles;
                            for (int ii = 1; ii < stairHandles.Count; ii++)
                            {
                                IFCAnyHandle railingLocalPlacement = stairRampInfo.LocalPlacements[ii];
                                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(railingLocalPlacement))
                                {
                                    IFCAnyHandle railingHndCopy = CopyRailingHandle(exporterIFC, element, catId, railingLocalPlacement, railing);
                                    stairRampInfo.AddComponent(ii, railingHndCopy);
                                    productWrapper.AddElement(element, railingHndCopy, (IFCLevelInfo)null, ecData, false, exportInfo);
                                    CategoryUtil.CreateMaterialAssociationWithShapeAspect(exporterIFC, element, railingHndCopy, bodyData.RepresentationItemInfo);
                                }
                            }

                            ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(hostId, stairRampInfo);
                        }
                    }
                    transaction.Commit();
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Export the individual part (IfcBuildingElementPart).
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="partElement">The part element to export.</param>
        /// <param name="geometryElement">The geometry of part.</param>
        /// <param name="productWrapper">The ProductWrapper object.</param>
        public static void ExportPart(ExporterIFC exporterIFC, Element partElement, ProductWrapper productWrapper,
                                      PlacementSetter placementSetter, IFCAnyHandle originalPlacement, IFCRange range, IFCExtrusionAxes ifcExtrusionAxes,
                                      Element hostElement, ElementId overrideLevelId, bool asBuildingElement)
        {
            if (!ElementFilteringUtil.IsElementVisible(partElement))
            {
                return;
            }

            Part part = partElement as Part;

            if (part == null)
            {
                return;
            }

            if (!asBuildingElement)
            {
                // 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>("IfcBuildingElementPart", out elementClassTypeEnum))
                {
                    if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                    {
                        return;
                    }
                }
            }
            else
            {
                string        ifcEnumType = null;
                IFCExportType exportType  = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType);

                // 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>(exportType.ToString(), out elementClassTypeEnum))
                {
                    if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                    {
                        return;
                    }
                }
            }

            PlacementSetter standalonePlacementSetter = null;
            bool            standaloneExport          = hostElement == null && !asBuildingElement;

            ElementId partExportLevel = null;

            if (standaloneExport || asBuildingElement)
            {
                partExportLevel = partElement.LevelId;
            }
            else
            {
                if (part.OriginalCategoryId != hostElement.Category.Id)
                {
                    return;
                }
                partExportLevel = hostElement.LevelId;
            }
            if (overrideLevelId != null)
            {
                partExportLevel = overrideLevelId;
            }

            if (ExporterCacheManager.PartExportedCache.HasExported(partElement.Id, partExportLevel))
            {
                return;
            }

            Options options   = GeometryUtil.GetIFCExportGeometryOptions();
            View    ownerView = partElement.Document.GetElement(partElement.OwnerViewId) as View;

            if (ownerView != null)
            {
                options.View = ownerView;
            }

            GeometryElement geometryElement = partElement.get_Geometry(options);

            if (geometryElement == null)
            {
                return;
            }

            try
            {
                IFCFile file = exporterIFC.GetFile();
                using (IFCTransaction transaction = new IFCTransaction(file))
                {
                    IFCAnyHandle partPlacement = null;
                    if (standaloneExport || asBuildingElement)
                    {
                        Transform orientationTrf = Transform.Identity;
                        standalonePlacementSetter = PlacementSetter.Create(exporterIFC, partElement, null, orientationTrf, partExportLevel);
                        partPlacement             = standalonePlacementSetter.LocalPlacement;
                    }
                    else
                    {
                        partPlacement = ExporterUtil.CreateLocalPlacement(file, originalPlacement, null);
                    }

                    bool validRange = (range != null && !MathUtil.IsAlmostZero(range.Start - range.End));

                    SolidMeshGeometryInfo solidMeshInfo;
                    if (validRange)
                    {
                        solidMeshInfo = GeometryUtil.GetSplitClippedSolidMeshGeometry(geometryElement, range);
                        if (solidMeshInfo.GetSolids().Count == 0 && solidMeshInfo.GetMeshes().Count == 0)
                        {
                            return;
                        }
                    }
                    else
                    {
                        solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement);
                    }

                    using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData())
                    {
                        extrusionCreationData.SetLocalPlacement(partPlacement);
                        extrusionCreationData.ReuseLocalPlacement   = false;
                        extrusionCreationData.PossibleExtrusionAxes = ifcExtrusionAxes;

                        IList <Solid> solids = solidMeshInfo.GetSolids();
                        IList <Mesh>  meshes = solidMeshInfo.GetMeshes();

                        ElementId catId     = CategoryUtil.GetSafeCategoryId(partElement);
                        ElementId hostCatId = CategoryUtil.GetSafeCategoryId(hostElement);

                        BodyData            bodyData            = null;
                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow);
                        if (solids.Count > 0 || meshes.Count > 0)
                        {
                            bodyData = BodyExporter.ExportBody(exporterIFC, partElement, catId, ElementId.InvalidElementId, solids, meshes,
                                                               bodyExporterOptions, extrusionCreationData);
                        }
                        else
                        {
                            IList <GeometryObject> geomlist = new List <GeometryObject>();
                            geomlist.Add(geometryElement);
                            bodyData = BodyExporter.ExportBody(exporterIFC, partElement, catId, ElementId.InvalidElementId, geomlist,
                                                               bodyExporterOptions, extrusionCreationData);
                        }

                        IFCAnyHandle bodyRep = bodyData.RepresentationHnd;
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep))
                        {
                            extrusionCreationData.ClearOpenings();
                            return;
                        }

                        IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();
                        representations.Add(bodyRep);

                        IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geometryElement, Transform.Identity);
                        if (boundingBoxRep != null)
                        {
                            representations.Add(boundingBoxRep);
                        }

                        IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);

                        IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;

                        string partGUID        = GUIDUtil.CreateGUID(partElement);
                        string partName        = NamingUtil.GetNameOverride(partElement, NamingUtil.GetIFCName(partElement));
                        string partDescription = NamingUtil.GetDescriptionOverride(partElement, null);
                        string partObjectType  = NamingUtil.GetObjectTypeOverride(partElement, NamingUtil.CreateIFCObjectName(exporterIFC, partElement));
                        string partTag         = NamingUtil.GetTagOverride(partElement, NamingUtil.CreateIFCElementId(partElement));

                        IFCAnyHandle ifcPart = null;
                        if (!asBuildingElement)
                        {
                            ifcPart = IFCInstanceExporter.CreateBuildingElementPart(file, partGUID, ownerHistory, partName, partDescription,
                                                                                    partObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, partTag);
                        }
                        else
                        {
                            string        ifcEnumType = null;
                            IFCExportType exportType  = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType);

                            string defaultValue = null;
                            // This replicates old functionality before IFC4 addition, where the default for slab was "FLOOR".
                            // Really the export layer table should be fixed for this case.
                            if (string.IsNullOrWhiteSpace(ifcEnumType) && hostCatId == new ElementId(BuiltInCategory.OST_Floors))
                            {
                                ifcEnumType = "FLOOR";
                            }
                            ifcEnumType = IFCValidateEntry.GetValidIFCType(hostElement, ifcEnumType, defaultValue);

                            switch (exportType)
                            {
                            case IFCExportType.IfcColumnType:
                                ifcPart = IFCInstanceExporter.CreateColumn(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                           extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            case IFCExportType.IfcCovering:
                                ifcPart = IFCInstanceExporter.CreateCovering(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                             extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            case IFCExportType.IfcFooting:
                                ifcPart = IFCInstanceExporter.CreateFooting(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                            extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            case IFCExportType.IfcPile:
                                ifcPart = IFCInstanceExporter.CreatePile(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType, null);
                                break;

                            case IFCExportType.IfcRoof:
                                ifcPart = IFCInstanceExporter.CreateRoof(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            case IFCExportType.IfcSlab:
                                ifcPart = IFCInstanceExporter.CreateSlab(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            case IFCExportType.IfcWall:
                                ifcPart = IFCInstanceExporter.CreateWall(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            default:
                                ifcPart = IFCInstanceExporter.CreateBuildingElementProxy(file, partGUID, ownerHistory, partName, partDescription,
                                                                                         partObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, partTag, null);
                                break;
                            }
                        }

                        bool            containedInLevel     = (standaloneExport || asBuildingElement);
                        PlacementSetter whichPlacementSetter = containedInLevel ? standalonePlacementSetter : placementSetter;
                        productWrapper.AddElement(partElement, ifcPart, whichPlacementSetter, extrusionCreationData, containedInLevel);

                        OpeningUtil.CreateOpeningsIfNecessary(ifcPart, partElement, extrusionCreationData, bodyData.OffsetTransform, exporterIFC,
                                                              extrusionCreationData.GetLocalPlacement(), whichPlacementSetter, productWrapper);

                        //Add the exported part to exported cache.
                        TraceExportedParts(partElement, partExportLevel, standaloneExport || asBuildingElement ? ElementId.InvalidElementId : hostElement.Id);

                        CategoryUtil.CreateMaterialAssociation(exporterIFC, ifcPart, bodyData.MaterialIds);

                        transaction.Commit();
                    }
                }
            }
            finally
            {
                if (standalonePlacementSetter != null)
                {
                    standalonePlacementSetter.Dispose();
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Exports curtain object as container.
        /// </summary>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="wallElement">
        /// The curtain wall element.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void ExportCurtainObjectCommonAsContainer(ICollection <ElementId> allSubElements, Element wallElement,
                                                                ExporterIFC exporterIFC, ProductWrapper origWrapper, PlacementSetter currSetter)
        {
            if (wallElement == null)
            {
                return;
            }

            string overrideCADLayer = null;

            ParameterUtil.GetStringValueFromElementOrSymbol(wallElement, "IFCCadLayer", out overrideCADLayer);

            using (ExporterStateManager.CADLayerOverrideSetter layerSetter = new ExporterStateManager.CADLayerOverrideSetter(overrideCADLayer))
            {
                HashSet <ElementId> alreadyVisited = new HashSet <ElementId>(); // just in case.
                Options             geomOptions    = GeometryUtil.GetIFCExportGeometryOptions();
                {
                    foreach (ElementId subElemId in allSubElements)
                    {
                        using (ProductWrapper productWrapper = ProductWrapper.Create(origWrapper))
                        {
                            Element subElem = wallElement.Document.GetElement(subElemId);
                            if (subElem == null)
                            {
                                continue;
                            }

                            if (alreadyVisited.Contains(subElem.Id))
                            {
                                continue;
                            }
                            alreadyVisited.Add(subElem.Id);

                            // Respect element visibility settings.
                            if (!ElementFilteringUtil.CanExportElement(exporterIFC, subElem, false) || !ElementFilteringUtil.IsElementVisible(subElem))
                            {
                                continue;
                            }

                            GeometryElement geomElem = subElem.get_Geometry(geomOptions);
                            if (geomElem == null)
                            {
                                continue;
                            }

                            try
                            {
                                if (subElem is FamilyInstance)
                                {
                                    string            ifcEnumType;
                                    IFCExportInfoPair exportType = ExporterUtil.GetExportType(exporterIFC, subElem, out ifcEnumType);

                                    if (subElem is Mullion)
                                    {
                                        if (ExporterCacheManager.ExportOptionsCache.ExportAs2x2)
                                        {
                                            ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper);
                                        }
                                        else
                                        {
                                            IFCAnyHandle currLocalPlacement = currSetter.LocalPlacement;

                                            if (exportType.ExportInstance == IFCEntityType.IfcCurtainWall)
                                            {
                                                // By default, panels and mullions are set to the same category as their parent.  In this case,
                                                // ask to get the exportType from the category id, since we don't want to inherit the parent class.
                                                exportType.SetValueWithPair(IFCEntityType.IfcMemberType);
                                                ifcEnumType = "MULLION";
                                            }

                                            FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem(exporterIFC, subElem as Mullion, exportType, ifcEnumType, productWrapper,
                                                                                                    ElementId.InvalidElementId, null, currLocalPlacement);
                                        }
                                    }
                                    else
                                    {
                                        FamilyInstance subFamInst = subElem as FamilyInstance;

                                        if (exportType.ExportInstance == IFCEntityType.IfcCurtainWall)
                                        {
                                            // By default, panels and mullions are set to the same category as their parent.  In this case,
                                            // ask to get the exportType from the category id, since we don't want to inherit the parent class.
                                            ElementId catId = CategoryUtil.GetSafeCategoryId(subElem);
                                            exportType = ElementFilteringUtil.GetExportTypeFromCategoryId(catId, out ifcEnumType);
                                        }


                                        if (ExporterCacheManager.ExportOptionsCache.ExportAs2x2)
                                        {
                                            if ((exportType.ExportInstance == IFCEntityType.UnKnown) ||
                                                (exportType.ExportInstance == IFCEntityType.IfcPlate) ||
                                                (exportType.ExportInstance == IFCEntityType.IfcMember))
                                            {
                                                exportType.SetValueWithPair(IFCEntityType.IfcBuildingElementProxy);
                                            }
                                        }
                                        else
                                        {
                                            if (exportType.ExportInstance == IFCEntityType.UnKnown)
                                            {
                                                ifcEnumType = "CURTAIN_PANEL";
                                                exportType.SetValueWithPair(IFCEntityType.IfcPlateType);
                                            }
                                        }

                                        IFCAnyHandle currLocalPlacement = currSetter.LocalPlacement;
                                        using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                                        {
                                            FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem(exporterIFC, subFamInst, exportType, ifcEnumType, productWrapper,
                                                                                                    ElementId.InvalidElementId, null, currLocalPlacement);
                                        }
                                    }
                                }
                                else if (subElem is CurtainGridLine)
                                {
                                    ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper);
                                }
                                else if (subElem is Wall)
                                {
                                    WallExporter.ExportWall(exporterIFC, null, subElem, null, geomElem, productWrapper);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ExporterUtil.IsFatalException(wallElement.Document, ex))
                                {
                                    throw ex;
                                }
                                continue;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Exports a generic family instance as IFC instance.
        /// </summary>
        /// <param name="type">The export type.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="familyInstance">The element.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        /// <param name="setter">The PlacementSetter.</param>
        /// <param name="extraParams">The extrusion creation data.</param>
        /// <param name="instanceGUID">The guid.</param>
        /// <param name="ownerHistory">The owner history handle.</param>
        /// <param name="instanceName">The name.</param>
        /// <param name="instanceDescription">The description.</param>
        /// <param name="instanceObjectType">The object type.</param>
        /// <param name="productRepresentation">The representation handle.</param>
        /// <param name="instanceTag">The tag for the entity, usually based on the element id.</param>
        /// <param name="ifcEnumType">The predefined type/shape type, if any, for the object.</param>
        /// <param name="overrideLocalPlacement">The local placement to use instead of the one in the placement setter, if appropriate.</param>
        /// <returns>The handle.</returns>
        public static IFCAnyHandle ExportGenericInstance(IFCExportInfoPair type,
                                                         ExporterIFC exporterIFC, Element familyInstance,
                                                         ProductWrapper wrapper, PlacementSetter setter, IFCExtrusionCreationData extraParams,
                                                         string instanceGUID, IFCAnyHandle ownerHistory, IFCAnyHandle productRepresentation,
                                                         string ifcEnumType, IFCAnyHandle overrideLocalPlacement)
        {
            IFCFile  file = exporterIFC.GetFile();
            Document doc  = familyInstance.Document;

            bool isRoomRelated      = IsRoomRelated(type);
            bool isChildInContainer = familyInstance.AssemblyInstanceId != ElementId.InvalidElementId;

            IFCAnyHandle localPlacementToUse = setter.LocalPlacement;
            ElementId    roomId = ElementId.InvalidElementId;

            if (isRoomRelated)
            {
                roomId = setter.UpdateRoomRelativeCoordinates(familyInstance, out localPlacementToUse);
            }

            //should remove the create method where there is no use of this handle for API methods
            //some places uses the return value of ExportGenericInstance as input parameter for API methods
            IFCAnyHandle instanceHandle = null;

            switch (type.ExportInstance)
            {
            case IFCEntityType.IfcBeam:
            {
                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "BEAM" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreateBeam(exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                localPlacementToUse, productRepresentation, preDefinedType);
                break;
            }

            case IFCEntityType.IfcColumn:
            {
                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "COLUMN" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreateColumn(exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                  localPlacementToUse, productRepresentation, preDefinedType);
                break;
            }

            case IFCEntityType.IfcCurtainWall:
            {
                instanceHandle = IFCInstanceExporter.CreateCurtainWall(exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                       localPlacementToUse, productRepresentation, ifcEnumType);
                break;
            }

            case IFCEntityType.IfcMember:
            {
                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "BRACE" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreateMember(exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                  localPlacementToUse, productRepresentation, preDefinedType);

                // Register the members's IFC handle for later use by truss export.
                ExporterCacheManager.ElementToHandleCache.Register(familyInstance.Id, instanceHandle);
                break;
            }

            case IFCEntityType.IfcPlate:
            {
                IFCAnyHandle localPlacement = localPlacementToUse;
                if (overrideLocalPlacement != null)
                {
                    isChildInContainer = true;
                    localPlacement     = overrideLocalPlacement;
                }

                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "NOTDEFINED" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreatePlate(exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                 localPlacement, productRepresentation, preDefinedType);
                break;
            }

            case IFCEntityType.IfcMechanicalFastener:
            {
                double?nominalDiameter = null;
                double?nominalLength   = null;

                double nominalDiameterVal, nominalLengthVal;
                if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalDiameter", out nominalDiameterVal) != null)
                {
                    nominalDiameter = UnitUtil.ScaleLength(nominalDiameterVal);
                }
                if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalLength", out nominalLengthVal) != null)
                {
                    nominalLength = UnitUtil.ScaleLength(nominalLengthVal);
                }

                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "NOTDEFINED" : ifcEnumType;

                instanceHandle = IFCInstanceExporter.CreateMechanicalFastener(exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                              localPlacementToUse, productRepresentation, nominalDiameter, nominalLength, preDefinedType);
                break;
            }

            case IFCEntityType.IfcRailing:
            {
                string            strEnumType;
                IFCExportInfoPair exportAs = ExporterUtil.GetExportType(exporterIFC, familyInstance, out strEnumType);
                if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                {
                    instanceHandle = IFCInstanceExporter.CreateRailing(exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                       localPlacementToUse, productRepresentation, GetPreDefinedType <Toolkit.IFC4.IFCRailingType>(familyInstance, strEnumType).ToString());
                }
                else
                {
                    instanceHandle = IFCInstanceExporter.CreateRailing(exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                       localPlacementToUse, productRepresentation, GetPreDefinedType <Toolkit.IFCRailingType>(familyInstance, strEnumType).ToString());
                }
                break;
            }

            case IFCEntityType.IfcSpace:
            {
                IFCInternalOrExternal internalOrExternal = CategoryUtil.IsElementExternal(familyInstance) ? IFCInternalOrExternal.External : IFCInternalOrExternal.Internal;

                instanceHandle = IFCInstanceExporter.CreateSpace(exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                 localPlacementToUse, productRepresentation, IFCElementComposition.Element, internalOrExternal, null);
                break;
            }

            default:
            {
                // !!! These entities are deprecated in IFC4 and will be made abstract in the next version.
                //     It is still kept as it is because if we generate an IfcBuildingElementProxy, teh connectivity will be lost
                if (ExporterCacheManager.ExportOptionsCache.ExportAs4 &&
                    (type.ExportInstance == IFCEntityType.IfcDistributionElement ||
                     type.ExportInstance == IFCEntityType.IfcEnergyConversionDevice ||
                     type.ExportInstance == IFCEntityType.IfcFlowController ||
                     type.ExportInstance == IFCEntityType.IfcFlowFitting ||
                     type.ExportInstance == IFCEntityType.IfcFlowMovingDevice ||
                     type.ExportInstance == IFCEntityType.IfcFlowSegment ||
                     type.ExportInstance == IFCEntityType.IfcFlowStorageDevice ||
                     type.ExportInstance == IFCEntityType.IfcFlowTerminal ||
                     type.ExportInstance == IFCEntityType.IfcFlowTreatmentDevice))
                {
                    // for IFC4, there are several entities that are valid in IFC2x3 but now have been made abstract or deprecated, so cannot be created. Create proxy instead.
                    //instanceHandle = IFCInstanceExporter.CreateBuildingElementProxy(file, instanceGUID, ownerHistory,
                    //    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                    //    Toolkit.IFC4.IFCBuildingElementProxyType.USERDEFINED.ToString());
                    instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(type, exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                                localPlacementToUse, productRepresentation);
                }
                else
                {
                    if (type.ExportInstance != IFCEntityType.UnKnown)
                    {
                        instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(type, exporterIFC, familyInstance, instanceGUID, ownerHistory,
                                                                                    localPlacementToUse, productRepresentation);
                    }
                }
                break;
            }
            }

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle))
            {
                bool containedInSpace = (roomId != ElementId.InvalidElementId);
                bool associateToLevel = containedInSpace ? false : !isChildInContainer;
                wrapper.AddElement(familyInstance, instanceHandle, setter, extraParams, associateToLevel);
                if (containedInSpace)
                {
                    ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, instanceHandle);
                }
            }
            return(instanceHandle);
        }
Esempio n. 15
0
        /// <summary>
        /// Exports a Group as an IfcGroup.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportGroupElement(ExporterIFC exporterIFC, Group element,
                                              ProductWrapper productWrapper)
        {
            if (element == null)
            {
                return(false);
            }

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

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                IFCAnyHandle groupHnd = null;

                string       guid         = GUIDUtil.CreateGUID(element);
                IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
                string       name         = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                string       description  = NamingUtil.GetDescriptionOverride(element, null);
                string       objectType   = NamingUtil.GetObjectTypeOverride(element, NamingUtil.GetFamilyAndTypeName(element));
                string       longName     = NamingUtil.GetLongNameOverride(element, null);

                string            ifcEnumType;
                IFCExportInfoPair exportAs = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);

                if (exportAs.ExportInstance == IFCEntityType.IfcGroup)
                {
                    groupHnd = IFCInstanceExporter.CreateGroup(file, guid, ownerHistory, name, description, objectType);
                }
                else if (!ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4)
                {
                    if (exportAs.ExportInstance == IFCEntityType.IfcBuildingSystem)
                    {
                        groupHnd = IFCInstanceExporter.CreateBuildingSystem(file, exportAs, guid, ownerHistory, name, description, objectType, longName);
                    }
                    else if (exportAs.ExportInstance == IFCEntityType.IfcFurniture)
                    {
                        groupHnd = IFCInstanceExporter.CreateGenericIFCEntity(exportAs, exporterIFC, element, guid, ownerHistory, null, null);
                    }
                }

                if (groupHnd == null)
                {
                    return(false);
                }

                productWrapper.AddElement(element, groupHnd, exportAs);

                GroupInfo groupInfo = ExporterCacheManager.GroupCache.RegisterGroup(element.Id, groupHnd);

                // Check or set the cached Group's export type
                if (groupInfo.GroupType.ExportInstance == IFCEntityType.UnKnown)
                {
                    ExporterCacheManager.GroupCache.RegisterGroupType(element.Id, exportAs);
                }
                else if (groupInfo.GroupType.ExportInstance != exportAs.ExportInstance)
                {
                    throw new InvalidOperationException("Inconsistent Group export entity type");
                }

                tr.Commit();
                return(true);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Exports a Group as an IfcGroup.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportGroupElement(ExporterIFC exporterIFC, Group element,
                                              ProductWrapper productWrapper)
        {
            if (element == null)
            {
                return(false);
            }

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

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                IFCAnyHandle groupHnd = null;

                string       guid         = GUIDUtil.CreateGUID(element);
                IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
                string       name         = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                string       description  = NamingUtil.GetDescriptionOverride(element, null);
                string       objectType   = NamingUtil.GetObjectTypeOverride(element, NamingUtil.GetFamilyAndTypeName(element));
                string       longName     = NamingUtil.GetLongNameOverride(element, null);

                string            ifcEnumType;
                IFCExportInfoPair exportAs = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);

                if (exportAs.ExportInstance == IFCEntityType.IfcGroup)
                {
                    groupHnd = IFCInstanceExporter.CreateGroup(file, guid, ownerHistory, name, description, objectType);
                }
                else if (!ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4)
                {
                    if (exportAs.ExportInstance == IFCEntityType.IfcBuildingSystem)
                    {
                        groupHnd = IFCInstanceExporter.CreateBuildingSystem(file, exportAs, guid, ownerHistory, name, description, objectType, longName);
                    }
                    else if (exportAs.ExportInstance == IFCEntityType.IfcFurniture)
                    {
                        groupHnd = IFCInstanceExporter.CreateGenericIFCEntity(exportAs, exporterIFC, element, guid, ownerHistory, null, null);
                    }
                }

                if (groupHnd == null)
                {
                    return(false);
                }

                GroupInfo groupInfo = ExporterCacheManager.GroupCache.RegisterGroup(element.Id, groupHnd);

                if (IFCAnyHandleUtil.IsSubTypeOf(groupHnd, IFCEntityType.IfcProduct))
                {
                    IFCAnyHandle overrideContainerHnd = null;
                    ElementId    overrideContainerId  = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd);

                    using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd))
                    {
                        IFCAnyHandle localPlacementToUse;
                        ElementId    roomId = setter.UpdateRoomRelativeCoordinates(element, out localPlacementToUse);

                        bool containedInSpace = (roomId != ElementId.InvalidElementId);
                        productWrapper.AddElement(element, groupHnd, setter.LevelInfo, null, !containedInSpace, exportAs);

                        if (containedInSpace)
                        {
                            ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, groupHnd);
                        }
                    }
                }
                else
                {
                    productWrapper.AddElement(element, groupHnd, exportAs);
                }

                // Check or set the cached Group's export type
                if (groupInfo.GroupType.ExportInstance == IFCEntityType.UnKnown)
                {
                    ExporterCacheManager.GroupCache.RegisterGroupType(element.Id, exportAs);
                }
                else if (groupInfo.GroupType.ExportInstance != exportAs.ExportInstance)
                {
                    throw new InvalidOperationException("Inconsistent Group export entity type");
                }

                tr.Commit();
                return(true);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Exports a CeilingAndFloor element to IFC.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="floor">The floor element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportCeilingAndFloorElement(ExporterIFC exporterIFC, CeilingAndFloor floorElement, GeometryElement geometryElement,
                                                        ProductWrapper productWrapper)
        {
            if (geometryElement == null)
            {
                return;
            }

            // export parts or not
            bool exportParts = PartExporter.CanExportParts(floorElement);

            if (exportParts && !PartExporter.CanExportElementInPartExport(floorElement, floorElement.LevelId, false))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            string        ifcEnumType;
            IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, floorElement, out ifcEnumType);

            // 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>(exportType.ToString(), out elementClassTypeEnum))
            {
                if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                {
                    return;
                }
            }


            using (IFCTransaction tr = new IFCTransaction(file))
            {
                bool canExportAsContainerOrWithExtrusionAnalyzer = (!exportParts && (floorElement is Floor));

                if (canExportAsContainerOrWithExtrusionAnalyzer)
                {
                    // Try to export the Floor slab as a container.  If that succeeds, we are done.
                    // If we do export the floor as a container, it will take care of the local placement and transform there, so we need to leave
                    // this out of the IFCTransformSetter and PlacementSetter scopes below, or else we'll get double transforms.
                    IFCAnyHandle floorHnd = RoofExporter.ExportRoofOrFloorAsContainer(exporterIFC, ifcEnumType, floorElement, geometryElement, productWrapper);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(floorHnd))
                    {
                        tr.Commit();
                        return;
                    }
                }

                IList <IFCAnyHandle> slabHnds        = new List <IFCAnyHandle>();
                IList <IFCAnyHandle> brepSlabHnds    = new List <IFCAnyHandle>();
                IList <IFCAnyHandle> nonBrepSlabHnds = new List <IFCAnyHandle>();

                using (IFCTransformSetter transformSetter = IFCTransformSetter.Create())
                {
                    using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, floorElement))
                    {
                        IFCAnyHandle localPlacement = placementSetter.LocalPlacement;
                        IFCAnyHandle ownerHistory   = ExporterCacheManager.OwnerHistoryHandle;

                        // The routine ExportExtrudedSlabOpenings is called if exportedAsInternalExtrusion is true, and it requires having a valid level association.
                        // Disable calling ExportSlabAsExtrusion if we can't handle potential openings.
                        bool canExportAsInternalExtrusion = placementSetter.LevelInfo != null;
                        bool exportedAsInternalExtrusion  = false;

                        ElementId catId = CategoryUtil.GetSafeCategoryId(floorElement);

                        IList <IFCAnyHandle>             prodReps        = new List <IFCAnyHandle>();
                        IList <ShapeRepresentationType>  repTypes        = new List <ShapeRepresentationType>();
                        IList <IList <CurveLoop> >       extrusionLoops  = new List <IList <CurveLoop> >();
                        IList <IFCExtrusionCreationData> loopExtraParams = new List <IFCExtrusionCreationData>();
                        Plane floorPlane = GeometryUtil.CreateDefaultPlane();

                        IList <IFCAnyHandle> localPlacements = new List <IFCAnyHandle>();

                        if (canExportAsContainerOrWithExtrusionAnalyzer)
                        {
                            Floor floor = floorElement as Floor;

                            // Next, try to use the ExtrusionAnalyzer for the limited cases it handles - 1 solid, no openings, end clippings only.
                            // Also limited to cases with line and arc boundaries.
                            //
                            SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement);
                            IList <Solid>         solids        = solidMeshInfo.GetSolids();
                            IList <Mesh>          meshes        = solidMeshInfo.GetMeshes();

                            if (solids.Count == 1 && meshes.Count == 0)
                            {
                                bool completelyClipped;
                                // floorExtrusionDirection is set to (0, 0, -1) because extrusionAnalyzerFloorPlane is computed from the top face of the floor
                                XYZ floorExtrusionDirection = new XYZ(0, 0, -1);
                                XYZ modelOrigin             = XYZ.Zero;

                                XYZ floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                                if (floorOrigin == null)
                                {
                                    // GetVerticalProjectionPoint may return null if FloorFace.Top is an edited face that doesn't
                                    // go through the Revit model origin.  We'll try the midpoint of the bounding box instead.
                                    BoundingBoxXYZ boundingBox = floorElement.get_BoundingBox(null);
                                    modelOrigin = (boundingBox.Min + boundingBox.Max) / 2.0;
                                    floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                                }

                                if (floorOrigin != null)
                                {
                                    XYZ   floorDir = floor.GetNormalAtVerticalProjectionPoint(floorOrigin, FloorFace.Top);
                                    Plane extrusionAnalyzerFloorBasePlane = GeometryUtil.CreatePlaneByNormalAtOrigin(floorDir);

                                    GenerateAdditionalInfo additionalInfo     = ExporterCacheManager.ExportOptionsCache.ExportAs4 ? GenerateAdditionalInfo.GenerateFootprint : GenerateAdditionalInfo.None;
                                    HandleAndData          floorAndProperties =
                                        ExtrusionExporter.CreateExtrusionWithClippingAndProperties(exporterIFC, floorElement,
                                                                                                   catId, solids[0], extrusionAnalyzerFloorBasePlane, floorOrigin, floorExtrusionDirection, null, out completelyClipped,
                                                                                                   addInfo: additionalInfo);
                                    if (completelyClipped)
                                    {
                                        return;
                                    }
                                    if (floorAndProperties.Handle != null)
                                    {
                                        IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();
                                        representations.Add(floorAndProperties.Handle);

                                        // Footprint representation will only be exported in export to IFC4
                                        if (((additionalInfo & GenerateAdditionalInfo.GenerateFootprint) != 0) && (floorAndProperties.FootprintInfo != null))
                                        {
                                            if (!(IFCAnyHandleUtil.IsNullOrHasNoValue(floorAndProperties.FootprintInfo.FootPrintHandle)))
                                            {
                                                representations.Add(floorAndProperties.FootprintInfo.FootPrintHandle);
                                            }
                                        }

                                        IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);
                                        prodReps.Add(prodRep);
                                        repTypes.Add(ShapeRepresentationType.SweptSolid);

                                        if (floorAndProperties.Data != null)
                                        {
                                            loopExtraParams.Add(floorAndProperties.Data);
                                        }
                                    }
                                }
                            }
                        }

                        // Use internal routine as backup that handles openings.
                        if (prodReps.Count == 0 && canExportAsInternalExtrusion)
                        {
                            //IList<IFCAnyHandle> prodRepsTmp = new List<IFCAnyHandle>();
                            exportedAsInternalExtrusion = ExporterIFCUtils.ExportSlabAsExtrusion(exporterIFC, floorElement,
                                                                                                 geometryElement, transformSetter, localPlacement, out localPlacements, out prodReps,
                                                                                                 out extrusionLoops, out loopExtraParams, floorPlane);
                            for (int ii = 0; ii < prodReps.Count; ii++)
                            {
                                // all are extrusions
                                repTypes.Add(ShapeRepresentationType.SweptSolid);

                                // Footprint representation will only be exported in export to IFC4
                                if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                                {
                                    // Get back the representations, we need to add the Footprint to it
                                    //IList<IFCAnyHandle> representations = IFCAnyHandleUtil.GetRepresentations(prodRepsTmp[ii]);

                                    if (extrusionLoops.Count > ii)
                                    {
                                        if (extrusionLoops[ii].Count > 0)
                                        {
                                            // Get the extrusion footprint using the first Curveloop. Transform needs to be obtained from the returned local placement
                                            Transform    lcs = ExporterIFCUtils.GetUnscaledTransform(exporterIFC, localPlacements[ii]);
                                            IFCAnyHandle footprintGeomRepItem = GeometryUtil.CreateIFCCurveFromCurveLoop(exporterIFC, extrusionLoops[ii][0], lcs, floorPlane.Normal);

                                            IFCAnyHandle        contextOfItemsFootprint = exporterIFC.Get3DContextHandle("FootPrint");
                                            ISet <IFCAnyHandle> repItem = new HashSet <IFCAnyHandle>();
                                            repItem.Add(footprintGeomRepItem);
                                            IFCAnyHandle footprintShapeRepresentation = RepresentationUtil.CreateBaseShapeRepresentation(exporterIFC, contextOfItemsFootprint, "FootPrint", "Curve2D", repItem);
                                            //representations.Add(footprintShapeRepresentation);
                                            IList <IFCAnyHandle> reps = new List <IFCAnyHandle>();
                                            reps.Add(footprintShapeRepresentation);
                                            IFCAnyHandleUtil.AddRepresentations(prodReps[ii], reps);
                                        }
                                    }
                                    //IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);
                                    //prodReps.Add(prodRep);
                                }
                                else
                                {
                                    //prodReps.Add(prodRepsTmp[ii]);
                                }

                                // We do not need the prodRepsTmp anymore, delete the handle:
                                //prodRepsTmp[ii].Delete();
                            }
                        }

                        if (prodReps.Count == 0)
                        {
                            using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                            {
                                // Brep representation using tesellation after ExportSlabAsExtrusion does not return prodReps
                                BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.Medium);
                                BodyData            bodyData;
                                IFCAnyHandle        prodDefHnd = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC,
                                                                                                                            floorElement, catId, geometryElement, bodyExporterOptions, null, ecData, out bodyData);
                                if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodDefHnd))
                                {
                                    ecData.ClearOpenings();
                                    return;
                                }

                                prodReps.Add(prodDefHnd);
                                repTypes.Add(bodyData.ShapeRepresentationType);
                            }
                        }

                        // Create the slab from either the extrusion or the BRep information.
                        string ifcGUID = GUIDUtil.CreateGUID(floorElement);

                        int numReps = exportParts ? 1 : prodReps.Count;

                        string entityType = null;

                        switch (exportType)
                        {
                        case IFCExportType.IfcFooting:
                            if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <Revit.IFC.Export.Toolkit.IFC4.IFCFootingType>(floorElement, ifcEnumType, null);
                            }
                            else
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <IFCFootingType>(floorElement, ifcEnumType, null);
                            }
                            break;

                        case IFCExportType.IfcCovering:
                            entityType = IFCValidateEntry.GetValidIFCType <IFCCoveringType>(floorElement, ifcEnumType, "FLOORING");
                            break;

                        case IFCExportType.IfcRamp:
                            if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <Revit.IFC.Export.Toolkit.IFC4.IFCRampType>(floorElement, ifcEnumType, null);
                            }
                            else
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <IFCRampType>(floorElement, ifcEnumType, null);
                            }
                            break;

                        default:
                            bool            isBaseSlab      = false;
                            AnalyticalModel analyticalModel = floorElement.GetAnalyticalModel();
                            if (analyticalModel != null)
                            {
                                AnalyzeAs slabFoundationType = analyticalModel.GetAnalyzeAs();
                                isBaseSlab = (slabFoundationType == AnalyzeAs.SlabOnGrade) || (slabFoundationType == AnalyzeAs.Mat);
                            }
                            entityType = IFCValidateEntry.GetValidIFCType <IFCSlabType>(floorElement, ifcEnumType, isBaseSlab ? "BASESLAB" : "FLOOR");
                            break;
                        }

                        for (int ii = 0; ii < numReps; ii++)
                        {
                            string ifcName        = NamingUtil.GetNameOverride(floorElement, NamingUtil.GetIFCNamePlusIndex(floorElement, ii == 0 ? -1 : ii + 1));
                            string ifcDescription = NamingUtil.GetDescriptionOverride(floorElement, null);
                            string ifcObjectType  = NamingUtil.GetObjectTypeOverride(floorElement, exporterIFC.GetFamilyName());
                            string ifcTag         = NamingUtil.GetTagOverride(floorElement, NamingUtil.CreateIFCElementId(floorElement));

                            string       currentGUID       = (ii == 0) ? ifcGUID : GUIDUtil.CreateGUID();
                            IFCAnyHandle localPlacementHnd = exportedAsInternalExtrusion ? localPlacements[ii] : localPlacement;

                            IFCAnyHandle slabHnd = null;

                            // TODO: replace with CreateGenericBuildingElement.
                            switch (exportType)
                            {
                            case IFCExportType.IfcFooting:
                                slabHnd = IFCInstanceExporter.CreateFooting(file, currentGUID, ownerHistory, ifcName,
                                                                            ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                            ifcTag, entityType);
                                break;

                            case IFCExportType.IfcCovering:
                                slabHnd = IFCInstanceExporter.CreateCovering(file, currentGUID, ownerHistory, ifcName,
                                                                             ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                             ifcTag, entityType);
                                break;

                            case IFCExportType.IfcRamp:
                                slabHnd = IFCInstanceExporter.CreateRamp(file, currentGUID, ownerHistory, ifcName,
                                                                         ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                         ifcTag, entityType);
                                break;

                            default:
                                //if ((canExportAsInternalExtrusion || exportedAsInternalExtrusion) && ExporterCacheManager.ExportOptionsCache.ExportAs4)
                                //{
                                //    slabHnd = IFCInstanceExporter.CreateSlabStandardCase(file, currentGUID, ownerHistory, ifcName,
                                //        ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                //        ifcTag, entityType);
                                //}
                                //else
                                slabHnd = IFCInstanceExporter.CreateSlab(file, currentGUID, ownerHistory, ifcName,
                                                                         ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                         ifcTag, entityType);
                                break;
                            }

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

                            if (exportParts)
                            {
                                PartExporter.ExportHostPart(exporterIFC, floorElement, slabHnd, productWrapper, placementSetter, localPlacementHnd, null);
                            }

                            slabHnds.Add(slabHnd);

                            if (!exportParts)
                            {
                                if (repTypes[ii] == ShapeRepresentationType.Brep)
                                {
                                    brepSlabHnds.Add(slabHnd);
                                }
                                else
                                {
                                    nonBrepSlabHnds.Add(slabHnd);
                                }
                            }
                        }

                        for (int ii = 0; ii < numReps; ii++)
                        {
                            IFCExtrusionCreationData loopExtraParam = ii < loopExtraParams.Count ? loopExtraParams[ii] : null;
                            productWrapper.AddElement(floorElement, slabHnds[ii], placementSetter, loopExtraParam, true);
                        }

                        // This call to the native function appears to create Brep opening also when appropriate. But the creation of the IFC instances is not
                        //   controllable from the managed code. Therefore in some cases BRep geometry for Opening will still be exported even in the Reference View
                        if (exportedAsInternalExtrusion)
                        {
                            ExporterIFCUtils.ExportExtrudedSlabOpenings(exporterIFC, floorElement, placementSetter.LevelInfo,
                                                                        localPlacements[0], slabHnds, extrusionLoops, floorPlane, productWrapper.ToNative());
                        }
                        //// For now we have to be content without IfcOpeningStandardCase from the openings created by this native call because it is too much to
                        ////    "reverse engineer" the IFChandle
                        //foreach (IFCAnyHandle slabHandle in slabHnds)
                        //{
                        //    updateOpeningProfileRep(exporterIFC, slabHandle);
                        //}
                    }

                    if (!exportParts)
                    {
                        if (nonBrepSlabHnds.Count > 0)
                        {
                            HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement, nonBrepSlabHnds,
                                                                         geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, false);
                        }
                        if (brepSlabHnds.Count > 0)
                        {
                            HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement, brepSlabHnds,
                                                                         geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, true);
                        }
                    }
                }
                tr.Commit();

                return;
            }
        }
Esempio n. 18
0
        /// <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.GetExportType(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>
        /// Exports an element as an IFC assembly.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportAssemblyInstanceElement(ExporterIFC exporterIFC, AssemblyInstance element,
                                                         ProductWrapper productWrapper)
        {
            if (element == null)
            {
                return(false);
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                IFCAnyHandle assemblyInstanceHnd = null;

                string          guid            = GUIDUtil.CreateGUID(element);
                IFCAnyHandle    ownerHistory    = ExporterCacheManager.OwnerHistoryHandle;
                IFCAnyHandle    localPlacement  = null;
                PlacementSetter placementSetter = null;
                IFCLevelInfo    levelInfo       = null;
                bool            relateToLevel   = true;

                string            ifcEnumType;
                IFCExportInfoPair exportAs = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);
                if (exportAs.ExportInstance == IFCEntityType.IfcSystem)
                {
                    string name        = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                    string description = NamingUtil.GetDescriptionOverride(element, null);
                    string objectType  = NamingUtil.GetObjectTypeOverride(element, NamingUtil.GetFamilyAndTypeName(element));
                    assemblyInstanceHnd = IFCInstanceExporter.CreateSystem(file, guid, ownerHistory, name, description, objectType);

                    // Create classification reference when System has classification filed name assigned to it
                    ClassificationUtil.CreateClassification(exporterIFC, file, element, assemblyInstanceHnd);

                    HashSet <IFCAnyHandle> relatedBuildings = new HashSet <IFCAnyHandle>();
                    relatedBuildings.Add(ExporterCacheManager.BuildingHandle);

                    IFCAnyHandle relServicesBuildings = IFCInstanceExporter.CreateRelServicesBuildings(file, GUIDUtil.CreateGUID(),
                                                                                                       ExporterCacheManager.OwnerHistoryHandle, null, null, assemblyInstanceHnd, relatedBuildings);

                    relateToLevel = false; // Already related to the building via IfcRelServicesBuildings.
                }
                else
                {
                    // Check for containment override
                    IFCAnyHandle overrideContainerHnd = null;
                    ElementId    overrideContainerId  = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd);

                    using (placementSetter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd))
                    {
                        IFCAnyHandle representation = null;

                        // We have limited support for exporting assemblies as other container types.
                        localPlacement = placementSetter.LocalPlacement;
                        levelInfo      = placementSetter.LevelInfo;

                        switch (exportAs.ExportInstance)
                        {
                        case IFCEntityType.IfcCurtainWall:
                            //case IFCExportType.IfcCurtainWallType:
                            //string cwPredefinedType = IFCValidateEntry.GetValidIFCPredefinedType(element, ifcEnumType, "IfcCurtainWallType");
                            assemblyInstanceHnd = IFCInstanceExporter.CreateCurtainWall(exporterIFC, element, guid,
                                                                                        ownerHistory, localPlacement, representation, ifcEnumType);
                            break;

                        case IFCEntityType.IfcRamp:
                            string rampPredefinedType = RampExporter.GetIFCRampType(ifcEnumType);
                            //rampPredefinedType = IFCValidateEntry.GetValidIFCPredefinedType(element, rampPredefinedType, "IfcRampType");
                            assemblyInstanceHnd = IFCInstanceExporter.CreateRamp(exporterIFC, element, guid,
                                                                                 ownerHistory, localPlacement, representation, rampPredefinedType);
                            break;

                        case IFCEntityType.IfcRoof:
                            //string roofPredefinedType = IFCValidateEntry.GetValidIFCPredefinedType(element, ifcEnumType, "IfcRoofType");
                            assemblyInstanceHnd = IFCInstanceExporter.CreateRoof(exporterIFC, element, guid,
                                                                                 ownerHistory, localPlacement, representation, ifcEnumType);
                            break;

                        case IFCEntityType.IfcStair:
                            string stairPredefinedType = StairsExporter.GetIFCStairType(ifcEnumType);
                            //stairPredefinedType = IFCValidateEntry.GetValidIFCPredefinedType(element, stairPredefinedType, "IfcStairType");
                            assemblyInstanceHnd = IFCInstanceExporter.CreateStair(exporterIFC, element, guid,
                                                                                  ownerHistory, localPlacement, representation, stairPredefinedType);
                            break;

                        case IFCEntityType.IfcWall:
                            //string wallPredefinedType = IFCValidateEntry.GetValidIFCPredefinedType(element, ifcEnumType, "IfcWallType");
                            assemblyInstanceHnd = IFCInstanceExporter.CreateWall(exporterIFC, element, guid,
                                                                                 ownerHistory, localPlacement, representation, ifcEnumType);
                            break;

                        default:
                            string objectType = NamingUtil.GetObjectTypeOverride(element, NamingUtil.GetFamilyAndTypeName(element));
                            IFCElementAssemblyType assemblyPredefinedType = GetPredefinedTypeFromObjectType(objectType);
                            assemblyInstanceHnd = IFCInstanceExporter.CreateElementAssembly(exporterIFC, element, guid,
                                                                                            ownerHistory, localPlacement, representation, IFCAssemblyPlace.NotDefined, assemblyPredefinedType);
                            break;
                        }
                    }
                }

                if (assemblyInstanceHnd == null)
                {
                    return(false);
                }

                // relateToLevel depends on how the AssemblyInstance is being mapped to IFC, above.
                productWrapper.AddElement(element, assemblyInstanceHnd, levelInfo, null, relateToLevel, exportAs);

                ExporterCacheManager.AssemblyInstanceCache.RegisterAssemblyInstance(element.Id, assemblyInstanceHnd);

                tr.Commit();
                return(true);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Split associated parts when host element is split by level.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="hostElement">The host element havign associtaed parts.</param>
        /// <param name="associatedPartsList">The list of associtated parts.</param>
        private static void SplitParts(ExporterIFC exporterIFC, Element hostElement, List <ElementId> associatedPartsList)
        {
            string        ifcEnumType;
            IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType);

            // Split the host to find the orphan parts.
            IList <ElementId> orphanLevels = new List <ElementId>();
            IList <ElementId> hostLevels   = new List <ElementId>();
            IList <IFCRange>  hostRanges   = new List <IFCRange>();

            LevelUtil.CreateSplitLevelRangesForElement(exporterIFC, exportType, hostElement, out hostLevels, out hostRanges);
            orphanLevels = hostLevels;

            // Split each Parts
            IList <ElementId> levels = new List <ElementId>();
            IList <IFCRange>  ranges = new List <IFCRange>();
            // Dictionary to storage the level and its parts.
            Dictionary <ElementId, List <KeyValuePair <Part, IFCRange> > > levelParts = new Dictionary <ElementId, List <KeyValuePair <Part, IFCRange> > >();

            foreach (ElementId partId in associatedPartsList)
            {
                Part part = hostElement.Document.GetElement(partId) as Part;
                LevelUtil.CreateSplitLevelRangesForElement(exporterIFC, exportType, part, out levels, out ranges);

                // if the parts are above top level, associate them with nearest bottom level.
                if (ranges.Count == 0)
                {
                    ElementId bottomLevelId = FindPartSplitLevel(exporterIFC, part);

                    if (bottomLevelId == ElementId.InvalidElementId)
                    {
                        bottomLevelId = part.LevelId;
                    }

                    if (!levelParts.ContainsKey(bottomLevelId))
                    {
                        levelParts.Add(bottomLevelId, new List <KeyValuePair <Part, IFCRange> >());
                    }

                    KeyValuePair <Part, IFCRange> splitPartRange = new KeyValuePair <Part, IFCRange>(part, null);
                    levelParts[bottomLevelId].Add(splitPartRange);

                    continue;
                }

                // The parts split by levels are stored in dictionary.
                for (int ii = 0; ii < ranges.Count; ii++)
                {
                    if (!levelParts.ContainsKey(levels[ii]))
                    {
                        levelParts.Add(levels[ii], new List <KeyValuePair <Part, IFCRange> >());
                    }

                    KeyValuePair <Part, IFCRange> splitPartRange = new KeyValuePair <Part, IFCRange>(part, ranges[ii]);
                    levelParts[levels[ii]].Add(splitPartRange);
                }

                if (levels.Count > hostLevels.Count)
                {
                    orphanLevels = orphanLevels.Union <ElementId>(levels).ToList();
                }
            }

            ExporterCacheManager.HostPartsCache.Register(hostElement.Id, levelParts);

            // The levels of orphan part.
            orphanLevels = orphanLevels.Where(number => !hostLevels.Contains(number)).ToList();
            List <KeyValuePair <ElementId, IFCRange> > levelRangePairList = new List <KeyValuePair <ElementId, IFCRange> >();

            foreach (ElementId orphanLevelId in orphanLevels)
            {
                IFCLevelInfo levelInfo = ExporterCacheManager.LevelInfoCache.GetLevelInfo(exporterIFC, orphanLevelId);
                if (levelInfo == null)
                {
                    continue;
                }
                double   levelHeight = ExporterCacheManager.LevelInfoCache.FindHeight(orphanLevelId);
                IFCRange levelRange  = new IFCRange(levelInfo.Elevation, levelInfo.Elevation + levelHeight);

                List <KeyValuePair <Part, IFCRange> > splitPartRangeList = new List <KeyValuePair <Part, IFCRange> >();
                splitPartRangeList = ExporterCacheManager.HostPartsCache.Find(hostElement.Id, orphanLevelId);
                IFCRange highestRange = levelRange;
                foreach (KeyValuePair <Part, IFCRange> partRange in splitPartRangeList)
                {
                    if (partRange.Value.End > highestRange.End)
                    {
                        highestRange = partRange.Value;
                    }
                }
                levelRangePairList.Add(new KeyValuePair <ElementId, IFCRange>(orphanLevelId, highestRange));
            }
            if (levelRangePairList.Count > 0)
            {
                ExporterCacheManager.DummyHostCache.Register(hostElement.Id, levelRangePairList);
            }
        }
        /// <summary>
        /// Exports a Rebar Coupler,
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="coupler">The RebarCoupler element.</param>
        /// <param name="productWrapper">The product wrapper.</param>
        public static void ExportCoupler(ExporterIFC exporterIFC, RebarCoupler coupler, ProductWrapper productWrapper)
        {
            if (coupler == null)
            {
                return;
            }

            FamilySymbol familySymbol = ExporterCacheManager.Document.GetElement(coupler.GetTypeId()) as FamilySymbol;

            if (familySymbol == 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>("IfcMechanicalFastener", out elementClassTypeEnum))
            {
                if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                {
                    return;
                }
            }

            ElementId categoryId = CategoryUtil.GetSafeCategoryId(coupler);

            IFCFile           file         = exporterIFC.GetFile();
            IFCAnyHandle      ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
            Options           options      = GeometryUtil.GetIFCExportGeometryOptions();;
            string            ifcEnumType;
            IFCExportInfoPair exportType = ExporterUtil.GetExportType(exporterIFC, coupler, out ifcEnumType);

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                FamilyTypeInfo currentTypeInfo = ExporterCacheManager.FamilySymbolToTypeInfoCache.Find(coupler.GetTypeId(), false, exportType.ExportType);
                bool           found           = currentTypeInfo.IsValid();
                if (!found)
                {
                    string typeObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, familySymbol);

                    HashSet <IFCAnyHandle> propertySetsOpt = new HashSet <IFCAnyHandle>();

                    GeometryElement exportGeometry = familySymbol.get_Geometry(options);

                    BodyData            bodyData            = null;
                    BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow);
                    bodyData = BodyExporter.ExportBody(exporterIFC, coupler, categoryId, ElementId.InvalidElementId, exportGeometry, bodyExporterOptions, null);

                    List <IFCAnyHandle> repMap = new List <IFCAnyHandle>();
                    IFCAnyHandle        origin = ExporterUtil.CreateAxis2Placement3D(file);;
                    repMap.Add(IFCInstanceExporter.CreateRepresentationMap(file, origin, bodyData.RepresentationHnd));

                    IFCAnyHandle styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, ifcEnumType, propertySetsOpt, repMap, coupler, familySymbol);

                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
                    {
                        string applicableOccurrence = NamingUtil.GetObjectTypeOverride(familySymbol, typeObjectType);
                        if (!string.IsNullOrEmpty(applicableOccurrence))
                        {
                            IFCAnyHandleUtil.SetAttribute(styleHandle, "ApplicableOccurrence", applicableOccurrence);
                        }
                        currentTypeInfo.Style = styleHandle;
                        ExporterCacheManager.FamilySymbolToTypeInfoCache.Register(coupler.GetTypeId(), false, exportType.ExportType, currentTypeInfo);
                    }
                }

                int nCouplerQuantity = coupler.GetCouplerQuantity();
                if (nCouplerQuantity <= 0)
                {
                    return;
                }

                ISet <IFCAnyHandle> createdRebarCouplerHandles = new HashSet <IFCAnyHandle>();
                string origInstanceName = NamingUtil.GetNameOverride(coupler, NamingUtil.GetIFCName(coupler));

                for (int idx = 0; idx < nCouplerQuantity; idx++)
                {
                    string instanceGUID = GUIDUtil.CreateSubElementGUID(coupler, idx);

                    IFCAnyHandle style = currentTypeInfo.Style;
                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(style))
                    {
                        return;
                    }

                    IList <IFCAnyHandle> repMapList = GeometryUtil.GetRepresentationMaps(style);
                    if (repMapList == null)
                    {
                        return;
                    }
                    if (repMapList.Count == 0)
                    {
                        return;
                    }

                    IList <IFCAnyHandle> shapeReps        = new List <IFCAnyHandle>();
                    IFCAnyHandle         contextOfItems3d = exporterIFC.Get3DContextHandle("Body");
                    ISet <IFCAnyHandle>  representations  = new HashSet <IFCAnyHandle>();
                    representations.Add(ExporterUtil.CreateDefaultMappedItem(file, repMapList[0], XYZ.Zero));
                    IFCAnyHandle shapeRep = RepresentationUtil.CreateBodyMappedItemRep(exporterIFC, coupler, categoryId, contextOfItems3d, representations);
                    shapeReps.Add(shapeRep);

                    IFCAnyHandle productRepresentation = IFCInstanceExporter.CreateProductDefinitionShape(exporterIFC.GetFile(), null, null, shapeReps);

                    Transform trf = coupler.GetCouplerPositionTransform(idx);

                    using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, coupler, trf, null))
                    {
                        IFCAnyHandle      instanceHandle     = null;
                        IFCExportInfoPair exportMechFastener = new IFCExportInfoPair();
                        exportMechFastener.SetValueWithPair(IFCEntityType.IfcMechanicalFastener);
                        instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportMechFastener, exporterIFC, coupler, instanceGUID, ownerHistory,
                                                                                    setter.LocalPlacement, productRepresentation);
                        string instanceName = NamingUtil.GetNameOverride(instanceHandle, coupler, origInstanceName + ": " + idx);
                        IFCAnyHandleUtil.SetAttribute(instanceHandle, "Name", instanceName);

                        if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                        {
                            // In IFC4 NominalDiameter and NominalLength attributes have been deprecated. PredefinedType attribute was added.
                            IFCAnyHandleUtil.SetAttribute(instanceHandle, "PredefinedType", Revit.IFC.Export.Toolkit.IFC4.IFCMechanicalFastenerType.USERDEFINED);
                        }
                        else
                        {
                            IFCAnyHandleUtil.SetAttribute(instanceHandle, "NominalDiameter", familySymbol.get_Parameter(BuiltInParameter.COUPLER_WIDTH).AsDouble());
                            IFCAnyHandleUtil.SetAttribute(instanceHandle, "NominalLength", familySymbol.get_Parameter(BuiltInParameter.COUPLER_LENGTH).AsDouble());
                        }

                        createdRebarCouplerHandles.Add(instanceHandle);

                        productWrapper.AddElement(coupler, instanceHandle, setter, null, true);
                    }
                }

                string couplerGUID = GUIDUtil.CreateGUID(coupler);

                if (nCouplerQuantity > 1)
                {
                    // Create a group to hold all of the created IFC entities, if the coupler aren't already in an assembly.
                    // We want to avoid nested groups of groups of couplers.
                    if (coupler.AssemblyInstanceId == ElementId.InvalidElementId)
                    {
                        string revitObjectType = exporterIFC.GetFamilyName();
                        string name            = NamingUtil.GetNameOverride(coupler, revitObjectType);
                        string description     = NamingUtil.GetDescriptionOverride(coupler, null);
                        string objectType      = NamingUtil.GetObjectTypeOverride(coupler, revitObjectType);

                        IFCAnyHandle rebarGroup = IFCInstanceExporter.CreateGroup(file, couplerGUID,
                                                                                  ownerHistory, name, description, objectType);

                        productWrapper.AddElement(coupler, rebarGroup);

                        IFCInstanceExporter.CreateRelAssignsToGroup(file, GUIDUtil.CreateGUID(), ownerHistory,
                                                                    null, null, createdRebarCouplerHandles, null, rebarGroup);
                    }
                }
                else
                {
                    // We will update the GUID of the one created element to be the element GUID.
                    // This will allow the IfcGUID parameter to be use/set if appropriate.
                    ExporterUtil.SetGlobalId(createdRebarCouplerHandles.ElementAt(0), couplerGUID);
                }

                tr.Commit();
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Exports a CeilingAndFloor element to IFC.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="floor">The floor element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportCeilingAndFloorElement(ExporterIFC exporterIFC, CeilingAndFloor floorElement, GeometryElement geometryElement,
                                                        ProductWrapper productWrapper)
        {
            if (geometryElement == null)
            {
                return;
            }

            // export parts or not
            bool exportParts = PartExporter.CanExportParts(floorElement);

            if (exportParts && !PartExporter.CanExportElementInPartExport(floorElement, floorElement.LevelId, false))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            string        ifcEnumType;
            IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, floorElement, out ifcEnumType);

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                bool canExportAsContainerOrWithExtrusionAnalyzer = (!exportParts && (floorElement is Floor));

                IList <IFCAnyHandle> slabHnds        = new List <IFCAnyHandle>();
                IList <IFCAnyHandle> brepSlabHnds    = new List <IFCAnyHandle>();
                IList <IFCAnyHandle> nonBrepSlabHnds = new List <IFCAnyHandle>();

                using (IFCTransformSetter transformSetter = IFCTransformSetter.Create())
                {
                    using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, floorElement))
                    {
                        IFCAnyHandle localPlacement = placementSetter.LocalPlacement;
                        IFCAnyHandle ownerHistory   = ExporterCacheManager.OwnerHistoryHandle;

                        // The routine ExportExtrudedSlabOpenings is called if exportedAsInternalExtrusion is true, and it requires having a valid level association.
                        // Disable calling ExportSlabAsExtrusion if we can't handle potential openings.
                        bool canExportAsInternalExtrusion = placementSetter.LevelInfo != null;
                        bool exportedAsInternalExtrusion  = false;

                        ElementId catId = CategoryUtil.GetSafeCategoryId(floorElement);

                        IList <IFCAnyHandle>             prodReps        = new List <IFCAnyHandle>();
                        IList <ShapeRepresentationType>  repTypes        = new List <ShapeRepresentationType>();
                        IList <IList <CurveLoop> >       extrusionLoops  = new List <IList <CurveLoop> >();
                        IList <IFCExtrusionCreationData> loopExtraParams = new List <IFCExtrusionCreationData>();
                        Plane floorPlane = GeometryUtil.CreateDefaultPlane();

                        IList <IFCAnyHandle> localPlacements = new List <IFCAnyHandle>();

                        if (canExportAsContainerOrWithExtrusionAnalyzer)
                        {
                            Floor floor = floorElement as Floor;

                            // First, try to use the ExtrusionAnalyzer for the limited cases it handles - 1 solid, no openings, end clippings only.
                            // Also limited to cases with line and arc boundaries.
                            //
                            SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement);
                            IList <Solid>         solids        = solidMeshInfo.GetSolids();
                            IList <Mesh>          meshes        = solidMeshInfo.GetMeshes();

                            if (solids.Count == 1 && meshes.Count == 0)
                            {
                                bool completelyClipped;
                                // floorExtrusionDirection is set to (0, 0, -1) because extrusionAnalyzerFloorPlane is computed from the top face of the floor
                                XYZ floorExtrusionDirection = new XYZ(0, 0, -1);
                                XYZ modelOrigin             = XYZ.Zero;

                                XYZ floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                                if (floorOrigin == null)
                                {
                                    // GetVerticalProjectionPoint may return null if FloorFace.Top is an edited face that doesn't
                                    // go thruough te Revit model orgigin.  We'll try the midpoint of the bounding box instead.
                                    BoundingBoxXYZ boundingBox = floorElement.get_BoundingBox(null);
                                    modelOrigin = (boundingBox.Min + boundingBox.Max) / 2.0;
                                    floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                                }

                                if (floorOrigin != null)
                                {
                                    XYZ   floorDir = floor.GetNormalAtVerticalProjectionPoint(floorOrigin, FloorFace.Top);
                                    Plane extrusionAnalyzerFloorPlane = new Plane(floorDir, floorOrigin);

                                    HandleAndData floorAndProperties =
                                        ExtrusionExporter.CreateExtrusionWithClippingAndProperties(exporterIFC, floorElement,
                                                                                                   catId, solids[0], extrusionAnalyzerFloorPlane, floorExtrusionDirection, null, out completelyClipped);
                                    if (completelyClipped)
                                    {
                                        return;
                                    }
                                    if (floorAndProperties.Handle != null)
                                    {
                                        IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();
                                        representations.Add(floorAndProperties.Handle);
                                        IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);
                                        prodReps.Add(prodRep);
                                        repTypes.Add(ShapeRepresentationType.SweptSolid);

                                        if (floorAndProperties.Data != null)
                                        {
                                            loopExtraParams.Add(floorAndProperties.Data);
                                        }
                                    }
                                }
                            }
                        }

                        // Use internal routine as backup that handles openings.
                        if (prodReps.Count == 0 && canExportAsInternalExtrusion)
                        {
                            exportedAsInternalExtrusion = ExporterIFCUtils.ExportSlabAsExtrusion(exporterIFC, floorElement,
                                                                                                 geometryElement, transformSetter, localPlacement, out localPlacements, out prodReps,
                                                                                                 out extrusionLoops, out loopExtraParams, floorPlane);
                            for (int ii = 0; ii < prodReps.Count; ii++)
                            {
                                // all are extrusions
                                repTypes.Add(ShapeRepresentationType.SweptSolid);
                            }
                        }

                        if (prodReps.Count == 0)
                        {
                            using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                            {
                                BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.Medium);
                                BodyData            bodyData;
                                IFCAnyHandle        prodDefHnd = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC,
                                                                                                                            floorElement, catId, geometryElement, bodyExporterOptions, null, ecData, out bodyData);
                                if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodDefHnd))
                                {
                                    ecData.ClearOpenings();
                                    return;
                                }

                                prodReps.Add(prodDefHnd);
                                repTypes.Add(bodyData.ShapeRepresentationType);
                            }
                        }

                        // Create the slab from either the extrusion or the BRep information.
                        string ifcGUID = GUIDUtil.CreateGUID(floorElement);

                        int numReps = exportParts ? 1 : prodReps.Count;

                        string entityType = null;

                        switch (exportType)
                        {
                        case IFCExportType.IfcFooting:
                            if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <Revit.IFC.Export.Toolkit.IFC4.IFCFootingType>(floorElement, ifcEnumType, null);
                            }
                            else
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <IFCFootingType>(floorElement, ifcEnumType, null);
                            }
                            break;

                        case IFCExportType.IfcCovering:
                            entityType = IFCValidateEntry.GetValidIFCType <IFCCoveringType>(floorElement, ifcEnumType, "FLOORING");
                            break;

                        case IFCExportType.IfcRamp:
                            if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <Revit.IFC.Export.Toolkit.IFC4.IFCRampType>(floorElement, ifcEnumType, null);
                            }
                            else
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <IFCRampType>(floorElement, ifcEnumType, null);
                            }
                            break;

                        default:
                            bool            isBaseSlab      = false;
                            AnalyticalModel analyticalModel = floorElement.GetAnalyticalModel();
                            if (analyticalModel != null)
                            {
                                AnalyzeAs slabFoundationType = analyticalModel.GetAnalyzeAs();
                                isBaseSlab = (slabFoundationType == AnalyzeAs.SlabOnGrade) || (slabFoundationType == AnalyzeAs.Mat);
                            }
                            entityType = IFCValidateEntry.GetValidIFCType <IFCSlabType>(floorElement, ifcEnumType, isBaseSlab ? "BASESLAB" : "FLOOR");
                            break;
                        }

                        for (int ii = 0; ii < numReps; ii++)
                        {
                            string ifcName        = NamingUtil.GetNameOverride(floorElement, NamingUtil.GetIFCNamePlusIndex(floorElement, ii == 0 ? -1 : ii + 1));
                            string ifcDescription = NamingUtil.GetDescriptionOverride(floorElement, null);
                            string ifcObjectType  = NamingUtil.GetObjectTypeOverride(floorElement, exporterIFC.GetFamilyName());
                            string ifcTag         = NamingUtil.GetTagOverride(floorElement, NamingUtil.CreateIFCElementId(floorElement));

                            string       currentGUID       = (ii == 0) ? ifcGUID : GUIDUtil.CreateGUID();
                            IFCAnyHandle localPlacementHnd = exportedAsInternalExtrusion ? localPlacements[ii] : localPlacement;

                            IFCAnyHandle slabHnd = null;

                            // TODO: replace with CreateGenericBuildingElement.
                            switch (exportType)
                            {
                            case IFCExportType.IfcFooting:
                                slabHnd = IFCInstanceExporter.CreateFooting(file, currentGUID, ownerHistory, ifcName,
                                                                            ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                            ifcTag, entityType);
                                break;

                            case IFCExportType.IfcCovering:
                                slabHnd = IFCInstanceExporter.CreateCovering(file, currentGUID, ownerHistory, ifcName,
                                                                             ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                             ifcTag, entityType);
                                break;

                            case IFCExportType.IfcRamp:
                                slabHnd = IFCInstanceExporter.CreateRamp(file, currentGUID, ownerHistory, ifcName,
                                                                         ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                         ifcTag, entityType);
                                break;

                            default:
                                slabHnd = IFCInstanceExporter.CreateSlab(file, currentGUID, ownerHistory, ifcName,
                                                                         ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                         ifcTag, entityType);
                                break;
                            }

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

                            if (exportParts)
                            {
                                PartExporter.ExportHostPart(exporterIFC, floorElement, slabHnd, productWrapper, placementSetter, localPlacementHnd, null);
                            }

                            slabHnds.Add(slabHnd);

                            if (!exportParts)
                            {
                                if (repTypes[ii] == ShapeRepresentationType.Brep)
                                {
                                    brepSlabHnds.Add(slabHnd);
                                }
                                else
                                {
                                    nonBrepSlabHnds.Add(slabHnd);
                                }
                            }
                        }

                        for (int ii = 0; ii < numReps; ii++)
                        {
                            IFCExtrusionCreationData loopExtraParam = ii < loopExtraParams.Count ? loopExtraParams[ii] : null;
                            productWrapper.AddElement(floorElement, slabHnds[ii], placementSetter, loopExtraParam, true);
                        }

                        // This call to the native function appears to create Brep opening also when appropriate. But the creation of the IFC instances is not
                        //   controllable from the managed code. Therefore in some cases BRep geometry for Opening will still be exported even in the Reference View
                        if (exportedAsInternalExtrusion)
                        {
                            ExporterIFCUtils.ExportExtrudedSlabOpenings(exporterIFC, floorElement, placementSetter.LevelInfo,
                                                                        localPlacements[0], slabHnds, extrusionLoops, floorPlane, productWrapper.ToNative());
                        }
                    }

                    if (!exportParts)
                    {
                        if (nonBrepSlabHnds.Count > 0)
                        {
                            HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement, nonBrepSlabHnds,
                                                                         geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, false);
                        }
                        if (brepSlabHnds.Count > 0)
                        {
                            HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement, brepSlabHnds,
                                                                         geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, true);
                        }
                    }
                }
                tr.Commit();

                return;
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Exports a CeilingAndFloor element to IFC.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="floor">The floor element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportCeilingAndFloorElement(ExporterIFC exporterIFC, CeilingAndFloor floorElement, GeometryElement geometryElement,
                                                        ProductWrapper productWrapper)
        {
            if (geometryElement == null)
            {
                return;
            }

            // export parts or not
            bool exportParts = PartExporter.CanExportParts(floorElement);

            if (exportParts && !PartExporter.CanExportElementInPartExport(floorElement, floorElement.LevelId, false))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            string               ifcEnumType;
            IFCExportInfoPair    exportType   = ExporterUtil.GetExportType(exporterIFC, floorElement, out ifcEnumType);
            IFCAnyHandle         type         = null;
            MaterialLayerSetInfo layersetInfo = null;

            if (!ElementFilteringUtil.IsElementVisible(floorElement))
            {
                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>(exportType.ExportInstance.ToString(), out elementClassTypeEnum) ||
                Enum.TryParse <Common.Enums.IFCEntityType>(exportType.ExportType.ToString(), out elementClassTypeEnum))
            {
                if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                {
                    return;
                }
            }

            Document doc = floorElement.Document;

            using (SubTransaction tempPartTransaction = new SubTransaction(doc))
            {
                // For IFC4RV export, Floor will be split into its parts(temporarily) in order to export the floor by its parts
                bool exportByComponents = ExporterUtil.ShouldExportByComponents(floorElement, exportParts);

                using (IFCTransaction tr = new IFCTransaction(file))
                {
                    bool canExportAsContainerOrWithExtrusionAnalyzer = (!exportParts && (floorElement is Floor));

                    if (canExportAsContainerOrWithExtrusionAnalyzer)
                    {
                        // Try to export the Floor slab as a container.  If that succeeds, we are done.
                        // If we do export the floor as a container, it will take care of the local placement and transform there, so we need to leave
                        // this out of the IFCTransformSetter and PlacementSetter scopes below, or else we'll get double transforms.
                        IFCAnyHandle floorHnd = RoofExporter.ExportRoofOrFloorAsContainer(exporterIFC, floorElement, geometryElement, productWrapper);
                        if (!IFCAnyHandleUtil.IsNullOrHasNoValue(floorHnd))
                        {
                            tr.Commit();
                            return;
                        }
                    }

                    IList <IFCAnyHandle> slabHnds        = new List <IFCAnyHandle>();
                    IList <IFCAnyHandle> brepSlabHnds    = new List <IFCAnyHandle>();
                    IList <IFCAnyHandle> nonBrepSlabHnds = new List <IFCAnyHandle>();

                    IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;

                    using (IFCTransformSetter transformSetter = IFCTransformSetter.Create())
                    {
                        // Check for containment override
                        IFCAnyHandle overrideContainerHnd = null;
                        ElementId    overrideContainerId  = ParameterUtil.OverrideContainmentParameter(exporterIFC, floorElement, out overrideContainerHnd);

                        using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, floorElement, null, null, overrideContainerId, overrideContainerHnd))
                        {
                            IFCAnyHandle localPlacement = placementSetter.LocalPlacement;

                            // The routine ExportExtrudedSlabOpenings is called if exportedAsInternalExtrusion is true, and it requires having a valid level association.
                            // Disable calling ExportSlabAsExtrusion if we can't handle potential openings.
                            bool canExportAsInternalExtrusion = placementSetter.LevelInfo != null;
                            bool exportedAsInternalExtrusion  = false;

                            ElementId catId = CategoryUtil.GetSafeCategoryId(floorElement);

                            IList <IFCAnyHandle>             prodReps        = new List <IFCAnyHandle>();
                            IList <ShapeRepresentationType>  repTypes        = new List <ShapeRepresentationType>();
                            IList <IList <CurveLoop> >       extrusionLoops  = new List <IList <CurveLoop> >();
                            IList <IFCExtrusionCreationData> loopExtraParams = new List <IFCExtrusionCreationData>();
                            Plane floorPlane = GeometryUtil.CreateDefaultPlane();

                            IList <IFCAnyHandle> localPlacements = new List <IFCAnyHandle>();

                            if (canExportAsContainerOrWithExtrusionAnalyzer)
                            {
                                Floor floor = floorElement as Floor;

                                // Next, try to use the ExtrusionAnalyzer for the limited cases it handles - 1 solid, no openings, end clippings only.
                                // Also limited to cases with line and arc boundaries.
                                //
                                SolidMeshGeometryInfo  solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement);
                                IList <Solid>          solids        = solidMeshInfo.GetSolids();
                                IList <Mesh>           meshes        = solidMeshInfo.GetMeshes();
                                IList <GeometryObject> gObjs         = FamilyExporterUtil.RemoveInvisibleSolidsAndMeshes(floorElement.Document, exporterIFC, ref solids, ref meshes);

                                if (solids.Count == 1 && meshes.Count == 0)
                                {
                                    bool completelyClipped;
                                    // floorExtrusionDirection is set to (0, 0, -1) because extrusionAnalyzerFloorPlane is computed from the top face of the floor
                                    XYZ floorExtrusionDirection = new XYZ(0, 0, -1);
                                    XYZ modelOrigin             = XYZ.Zero;

                                    XYZ floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                                    if (floorOrigin == null)
                                    {
                                        // GetVerticalProjectionPoint may return null if FloorFace.Top is an edited face that doesn't
                                        // go through the Revit model origin.  We'll try the midpoint of the bounding box instead.
                                        BoundingBoxXYZ boundingBox = floorElement.get_BoundingBox(null);
                                        modelOrigin = (boundingBox.Min + boundingBox.Max) / 2.0;
                                        floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                                    }

                                    if (floorOrigin != null)
                                    {
                                        XYZ   floorDir = floor.GetNormalAtVerticalProjectionPoint(floorOrigin, FloorFace.Top);
                                        Plane extrusionAnalyzerFloorBasePlane = GeometryUtil.CreatePlaneByNormalAtOrigin(floorDir);

                                        GenerateAdditionalInfo additionalInfo = GenerateAdditionalInfo.GenerateBody;
                                        additionalInfo |= ExporterCacheManager.ExportOptionsCache.ExportAs4 ?
                                                          GenerateAdditionalInfo.GenerateFootprint : GenerateAdditionalInfo.None;

                                        // Skip generate body item for IFC4RV. It will be handled later in PartExporter.ExportHostPartAsShapeAspects()
                                        if (exportByComponents)
                                        {
                                            additionalInfo &= ~GenerateAdditionalInfo.GenerateBody;
                                        }

                                        HandleAndData floorAndProperties =
                                            ExtrusionExporter.CreateExtrusionWithClippingAndProperties(exporterIFC, floorElement,
                                                                                                       catId, solids[0], extrusionAnalyzerFloorBasePlane, floorOrigin, floorExtrusionDirection, null, out completelyClipped,
                                                                                                       addInfo: additionalInfo);
                                        if (completelyClipped)
                                        {
                                            return;
                                        }

                                        IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();
                                        if (floorAndProperties.Handle != null)
                                        {
                                            representations.Add(floorAndProperties.Handle);
                                            repTypes.Add(ShapeRepresentationType.SweptSolid);
                                        }

                                        // Footprint representation will only be exported in export to IFC4
                                        if (((additionalInfo & GenerateAdditionalInfo.GenerateFootprint) != 0) && (floorAndProperties.FootprintInfo != null))
                                        {
                                            IFCAnyHandle footprintShapeRep = floorAndProperties.FootprintInfo.CreateFootprintShapeRepresentation(exporterIFC);
                                            representations.Add(footprintShapeRep);
                                        }

                                        if (exportByComponents)
                                        {
                                            IFCAnyHandle prodRep = RepresentationUtil.CreateProductDefinitionShapeWithoutBodyRep(exporterIFC, floorElement, catId, geometryElement, representations);
                                            prodReps.Add(prodRep);
                                        }
                                        else if (representations.Count > 0 && floorAndProperties.Handle != null) // Only when at least the body rep exists will come here
                                        {
                                            IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);
                                            prodReps.Add(prodRep);
                                        }

                                        if (floorAndProperties.Data != null)
                                        {
                                            loopExtraParams.Add(floorAndProperties.Data);
                                        }
                                    }
                                }
                            }

                            // Use internal routine as backup that handles openings.
                            if (prodReps.Count == 0 && canExportAsInternalExtrusion && !exportByComponents)
                            {
                                exportedAsInternalExtrusion = ExporterIFCUtils.ExportSlabAsExtrusion(exporterIFC, floorElement,
                                                                                                     geometryElement, transformSetter, localPlacement, out localPlacements, out prodReps,
                                                                                                     out extrusionLoops, out loopExtraParams, floorPlane);
                                PotentiallyFixPresentationLayerAssignment(floorElement, prodReps);
                                for (int ii = 0; ii < prodReps.Count; ii++)
                                {
                                    // all are extrusions
                                    repTypes.Add(ShapeRepresentationType.SweptSolid);

                                    // Footprint representation will only be exported in export to IFC4
                                    if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                                    {
                                        if (extrusionLoops.Count > ii)
                                        {
                                            if (extrusionLoops[ii].Count > 0)
                                            {
                                                // Get the extrusion footprint using the first Curveloop. Transform needs to be obtained from the returned local placement
                                                Transform    lcs = ExporterIFCUtils.GetUnscaledTransform(exporterIFC, localPlacements[ii]);
                                                IFCAnyHandle footprintGeomRepItem = GeometryUtil.CreateIFCCurveFromCurveLoop(exporterIFC, extrusionLoops[ii][0], lcs, floorPlane.Normal);

                                                IFCAnyHandle        contextOfItemsFootprint = exporterIFC.Get3DContextHandle("FootPrint");
                                                ISet <IFCAnyHandle> repItem = new HashSet <IFCAnyHandle>();
                                                repItem.Add(footprintGeomRepItem);
                                                IFCAnyHandle         footprintShapeRepresentation = RepresentationUtil.CreateBaseShapeRepresentation(exporterIFC, contextOfItemsFootprint, "FootPrint", "Curve2D", repItem);
                                                IList <IFCAnyHandle> reps = new List <IFCAnyHandle>();
                                                reps.Add(footprintShapeRepresentation);
                                                IFCAnyHandleUtil.AddRepresentations(prodReps[ii], reps);
                                            }
                                        }
                                    }
                                }
                            }

                            IFCAnyHandle prodDefHnd;
                            if (prodReps.Count == 0)
                            {
                                if (exportByComponents)
                                {
                                    prodDefHnd = RepresentationUtil.CreateProductDefinitionShapeWithoutBodyRep(exporterIFC, floorElement, catId, geometryElement, null);
                                    prodReps.Add(prodDefHnd);
                                }
                                else
                                {
                                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                                    {
                                        // Brep representation using tesellation after ExportSlabAsExtrusion does not return prodReps
                                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.Medium);
                                        BodyData            bodyData;
                                        prodDefHnd = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC,
                                                                                                                floorElement, catId, geometryElement, bodyExporterOptions, null, ecData, out bodyData);
                                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodDefHnd))
                                        {
                                            ecData.ClearOpenings();
                                            return;
                                        }

                                        prodReps.Add(prodDefHnd);
                                        repTypes.Add(bodyData.ShapeRepresentationType);
                                    }
                                }
                            }

                            // Create the slab from either the extrusion or the BRep information.
                            string ifcGUID = GUIDUtil.CreateGUID(floorElement);

                            int numReps = exportParts ? 1 : prodReps.Count;

                            // Deal with a couple of cases that have non-standard defaults.
                            switch (exportType.ExportInstance)
                            {
                            case IFCEntityType.IfcCovering:
                                exportType.ValidatedPredefinedType = IFCValidateEntry.GetValidIFCType <IFCCoveringType>(floorElement, ifcEnumType, "FLOORING");
                                break;

                            case IFCEntityType.IfcSlab:
                                bool            isBaseSlab      = false;
                                AnalyticalModel analyticalModel = floorElement.GetAnalyticalModel();
                                if (analyticalModel != null)
                                {
                                    AnalyzeAs slabFoundationType = analyticalModel.GetAnalyzeAs();
                                    isBaseSlab = (slabFoundationType == AnalyzeAs.SlabOnGrade) || (slabFoundationType == AnalyzeAs.Mat);
                                }
                                exportType.ValidatedPredefinedType = IFCValidateEntry.GetValidIFCType <IFCSlabType>(floorElement, ifcEnumType, isBaseSlab ? "BASESLAB" : "FLOOR");
                                break;
                            }

                            for (int ii = 0; ii < numReps; ii++)
                            {
                                string ifcName = NamingUtil.GetNameOverride(floorElement, NamingUtil.GetIFCNamePlusIndex(floorElement, ii == 0 ? -1 : ii + 1));

                                string       currentGUID       = (ii == 0) ? ifcGUID : GUIDUtil.CreateGUID();
                                IFCAnyHandle localPlacementHnd = exportedAsInternalExtrusion ? localPlacements[ii] : localPlacement;

                                IFCAnyHandle slabHnd = null;
                                slabHnd = IFCInstanceExporter.CreateGenericIFCEntity(exportType, exporterIFC, floorElement, currentGUID, ownerHistory,
                                                                                     localPlacementHnd, exportParts ? null : prodReps[ii]);
                                if (IFCAnyHandleUtil.IsNullOrHasNoValue(slabHnd))
                                {
                                    return;
                                }

                                if (!string.IsNullOrEmpty(ifcName))
                                {
                                    IFCAnyHandleUtil.OverrideNameAttribute(slabHnd, ifcName);
                                }

                                // Pre IFC4 Slab does not have PredefinedType
                                if (!string.IsNullOrEmpty(exportType.ValidatedPredefinedType) && !ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4)
                                {
                                    IFCAnyHandleUtil.SetAttribute(slabHnd, "PredefinedType", exportType.ValidatedPredefinedType, true);
                                }
                                if (exportParts && !ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
                                {
                                    PartExporter.ExportHostPart(exporterIFC, floorElement, slabHnd, productWrapper, placementSetter, localPlacementHnd, null);
                                }
                                else if (exportByComponents)
                                {
                                    IFCExtrusionCreationData partECData            = new IFCExtrusionCreationData();
                                    IFCAnyHandle             hostShapeRepFromParts = PartExporter.ExportHostPartAsShapeAspects(exporterIFC, floorElement, prodReps[ii],
                                                                                                                               productWrapper, placementSetter, localPlacement, ElementId.InvalidElementId, out layersetInfo, partECData);
                                    loopExtraParams.Add(partECData);
                                }

                                slabHnds.Add(slabHnd);

                                // For IFC4RV, export of the geometry is already handled in PartExporter.ExportHostPartAsShapeAspects()
                                if (!exportParts && !exportByComponents)
                                {
                                    if (repTypes[ii] == ShapeRepresentationType.Brep || repTypes[ii] == ShapeRepresentationType.Tessellation)
                                    {
                                        brepSlabHnds.Add(slabHnd);
                                    }
                                    else
                                    {
                                        nonBrepSlabHnds.Add(slabHnd);
                                    }
                                }
                            }

                            for (int ii = 0; ii < numReps; ii++)
                            {
                                IFCExtrusionCreationData loopExtraParam = ii < loopExtraParams.Count ? loopExtraParams[ii] : null;
                                productWrapper.AddElement(floorElement, slabHnds[ii], placementSetter, loopExtraParam, true, exportType);

                                type = ExporterUtil.CreateGenericTypeFromElement(floorElement, exportType, file, ownerHistory, exportType.ValidatedPredefinedType, productWrapper);
                                ExporterCacheManager.TypeRelationsCache.Add(type, slabHnds[ii]);

                                ExporterUtil.AddIntoComplexPropertyCache(slabHnds[ii], layersetInfo);
                            }

                            // This call to the native function appears to create Brep opening also when appropriate. But the creation of the IFC instances is not
                            //   controllable from the managed code. Therefore in some cases BRep geometry for Opening will still be exported even in the Reference View
                            if (exportedAsInternalExtrusion)
                            {
                                ISet <IFCAnyHandle> oldCreatedObjects = productWrapper.GetAllObjects();
                                ExporterIFCUtils.ExportExtrudedSlabOpenings(exporterIFC, floorElement, placementSetter.LevelInfo,
                                                                            localPlacements[0], slabHnds, extrusionLoops, floorPlane, productWrapper.ToNative());
                                ISet <IFCAnyHandle> newCreatedObjects = productWrapper.GetAllObjects();
                                newCreatedObjects.ExceptWith(oldCreatedObjects);
                                PotentiallyFixPresentationLayerAssignment(floorElement, newCreatedObjects);
                            }
                        }

                        if (!exportParts)
                        {
                            if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
                            {
                                HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement, productWrapper.GetAnElement(),
                                                                             geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, false, type);
                            }
                            else
                            {
                                if (nonBrepSlabHnds.Count > 0)
                                {
                                    HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement, nonBrepSlabHnds,
                                                                                 geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, false, type);
                                }

                                if (brepSlabHnds.Count > 0)
                                {
                                    HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement, brepSlabHnds,
                                                                                 geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, true, type);
                                }
                            }
                        }
                    }

                    tr.Commit();
                    return;
                }
            }
        }
Esempio n. 24
0
        /// <summary>
        ///  Exports a roof or floor as a container of multiple roof slabs.  Returns the handle, if successful.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="element">The roof or floor element.</param>
        /// <param name="geometry">The geometry of the element.</param>
        /// <param name="productWrapper">The product wrapper.</param>
        /// <returns>The roof handle.</returns>
        /// <remarks>For floors, if there is only one component, return null, as we do not want to create a container.</remarks>
        public static IFCAnyHandle ExportRoofOrFloorAsContainer(ExporterIFC exporterIFC,
                                                                Element element, GeometryElement geometry, ProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            // We support ExtrusionRoofs, FootPrintRoofs, and Floors only.
            bool elementIsRoof  = (element is ExtrusionRoof) || (element is FootPrintRoof);
            bool elementIsFloor = (element is Floor);

            if (!elementIsRoof && !elementIsFloor)
            {
                return(null);
            }

            string            ifcEnumType;
            IFCExportInfoPair roofExportType = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);

            if (roofExportType.IsUnKnown)
            {
                IFCEntityType elementClassTypeEnum =
                    elementIsFloor ? IFCEntityType.IfcSlab: IFCEntityType.IfcRoof;
                roofExportType = new IFCExportInfoPair(elementClassTypeEnum, "");
            }

            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(roofExportType.ExportType))
            {
                return(null);
            }

            Document doc = element.Document;

            using (SubTransaction tempPartTransaction = new SubTransaction(doc))
            {
                MaterialLayerSetInfo layersetInfo = new MaterialLayerSetInfo(exporterIFC, element, productWrapper);
                bool hasLayers = false;
                if (layersetInfo.MaterialIds.Count > 1)
                {
                    hasLayers = true;
                }
                bool exportByComponents = ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView && hasLayers;

                using (IFCTransaction transaction = new IFCTransaction(file))
                {
                    // Check for containment override
                    IFCAnyHandle overrideContainerHnd = null;
                    ElementId    overrideContainerId  = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd);

                    // We want to delay creating entity handles until as late as possible, so that if we abort the IFC transaction,
                    // we don't have to delete elements.  This is both for performance reasons and to potentially extend the number
                    // of projects that can be exported by reducing (a small amount) of waste.
                    IList <HostObjectSubcomponentInfo> hostObjectSubcomponents = null;
                    try
                    {
                        hostObjectSubcomponents = ExporterIFCUtils.ComputeSubcomponents(element as HostObject);
                    }
                    catch
                    {
                        return(null);
                    }

                    if (hostObjectSubcomponents == null)
                    {
                        return(null);
                    }

                    int numSubcomponents = hostObjectSubcomponents.Count;
                    if (numSubcomponents == 0 || (elementIsFloor && numSubcomponents == 1))
                    {
                        return(null);
                    }

                    using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd))
                    {
                        IFCAnyHandle localPlacement = setter.LocalPlacement;


                        IFCAnyHandle hostObjectHandle = null;
                        try
                        {
                            using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData())
                            {
                                IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
                                extrusionCreationData.SetLocalPlacement(localPlacement);
                                extrusionCreationData.ReuseLocalPlacement = true;

                                using (TransformSetter trfSetter = TransformSetter.Create())
                                {
                                    IList <GeometryObject> geometryList = new List <GeometryObject>();
                                    geometryList.Add(geometry);
                                    trfSetter.InitializeFromBoundingBox(exporterIFC, geometryList, extrusionCreationData);

                                    IFCAnyHandle prodRepHnd = null;

                                    string elementGUID = GUIDUtil.CreateGUID(element);

                                    hostObjectHandle = IFCInstanceExporter.CreateGenericIFCEntity(
                                        roofExportType, exporterIFC, element, elementGUID, ownerHistory,
                                        localPlacement, prodRepHnd);

                                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(hostObjectHandle))
                                    {
                                        return(null);
                                    }

                                    IList <IFCAnyHandle> elementHandles = new List <IFCAnyHandle>();
                                    elementHandles.Add(hostObjectHandle);

                                    // If element is floor, then the profile curve loop of hostObjectSubComponent is computed from the top face of the floor
                                    // else if element is roof, then the profile curve loop is taken from the bottom face of the roof instead
                                    XYZ extrusionDir = elementIsFloor ? new XYZ(0, 0, -1) : new XYZ(0, 0, 1);

                                    ElementId catId = CategoryUtil.GetSafeCategoryId(element);

                                    IList <IFCAnyHandle> slabHandles = new List <IFCAnyHandle>();

                                    IList <CurveLoop> hostObjectOpeningLoops = new List <CurveLoop>();
                                    double            maximumScaledDepth     = 0.0;

                                    using (IFCExtrusionCreationData slabExtrusionCreationData = new IFCExtrusionCreationData())
                                    {
                                        slabExtrusionCreationData.SetLocalPlacement(extrusionCreationData.GetLocalPlacement());
                                        slabExtrusionCreationData.ReuseLocalPlacement = false;
                                        slabExtrusionCreationData.ForceOffset         = true;

                                        int    loopNum         = 0;
                                        int    subElementStart = elementIsRoof ? (int)IFCRoofSubElements.RoofSlabStart : (int)IFCSlabSubElements.SubSlabStart;
                                        string subSlabType     = roofExportType.ValidatedPredefinedType;

                                        foreach (HostObjectSubcomponentInfo hostObjectSubcomponent in hostObjectSubcomponents)
                                        {
                                            trfSetter.InitializeFromBoundingBox(exporterIFC, geometryList, slabExtrusionCreationData);
                                            Plane     plane = hostObjectSubcomponent.GetPlane();
                                            Transform lcs   = GeometryUtil.CreateTransformFromPlane(plane);

                                            IList <CurveLoop> curveLoops = new List <CurveLoop>();

                                            CurveLoop slabCurveLoop = hostObjectSubcomponent.GetCurveLoop();
                                            curveLoops.Add(slabCurveLoop);
                                            double slope                    = Math.Abs(plane.Normal.Z);
                                            double scaledDepth              = UnitUtil.ScaleLength(hostObjectSubcomponent.Depth);
                                            double scaledExtrusionDepth     = scaledDepth * slope;
                                            IList <IFCAnyHandle> shapeReps  = new List <IFCAnyHandle>();
                                            IFCAnyHandle         repHnd     = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                                            string       shapeIdent         = "Body";
                                            IFCAnyHandle contextOfItems     = exporterIFC.Get3DContextHandle(shapeIdent);
                                            string       representationType = ShapeRepresentationType.SweptSolid.ToString();

                                            // Create representation items based on the layers
                                            // Because in this case, the Roof components are not derived from Parts, but by "splitting" geometry part that can be extruded,
                                            //    the creation of the Items for IFC4RV will be different by using "manual" split based on the layer thickness
                                            HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>();
                                            if (!exportByComponents)
                                            {
                                                IFCAnyHandle itemShapeRep = ExtrusionExporter.CreateExtrudedSolidFromCurveLoop(exporterIFC, null, curveLoops, lcs, extrusionDir, scaledExtrusionDepth, false);
                                                if (IFCAnyHandleUtil.IsNullOrHasNoValue(itemShapeRep))
                                                {
                                                    productWrapper.ClearInternalHandleWrapperData(element);
                                                    return(null);
                                                }
                                                ElementId matId = HostObjectExporter.GetFirstLayerMaterialId(element as HostObject);
                                                BodyExporter.CreateSurfaceStyleForRepItem(exporterIFC, element.Document, itemShapeRep, matId);
                                                bodyItems.Add(itemShapeRep);
                                            }
                                            else
                                            {
                                                double scaleProj = extrusionDir.DotProduct(plane.Normal);
                                                foreach (Tuple <ElementId, string, double> matLayerInfo in layersetInfo.MaterialIds)
                                                {
                                                    double       itemExtrDepth = matLayerInfo.Item3;
                                                    IFCAnyHandle itemShapeRep  = ExtrusionExporter.CreateExtrudedSolidFromCurveLoop(exporterIFC, null, curveLoops, lcs, extrusionDir, itemExtrDepth, false);
                                                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(itemShapeRep))
                                                    {
                                                        productWrapper.ClearInternalHandleWrapperData(element);
                                                        return(null);
                                                    }

                                                    //ElementId matId = HostObjectExporter.GetFirstLayerMaterialId(element as HostObject);
                                                    BodyExporter.CreateSurfaceStyleForRepItem(exporterIFC, element.Document, itemShapeRep, matLayerInfo.Item1);

                                                    bodyItems.Add(itemShapeRep);
                                                    IFCAnyHandle representationOfItem = RepresentationUtil.CreateShapeRepresentation(exporterIFC, element, catId, contextOfItems, shapeIdent,
                                                                                                                                     representationType, new HashSet <IFCAnyHandle>()
                                                    {
                                                        itemShapeRep
                                                    });
                                                    IFCAnyHandle shapeAspect = IFCInstanceExporter.CreateShapeAspect(file, new List <IFCAnyHandle>()
                                                    {
                                                        representationOfItem
                                                    }, matLayerInfo.Item2, null, null, repHnd);

                                                    XYZ offset = new XYZ(0, 0, itemExtrDepth / scaleProj); // offset is calculated as extent in the direction of extrusion
                                                    lcs.Origin += offset;
                                                }
                                            }

                                            IFCAnyHandle shapeRep = RepresentationUtil.CreateSweptSolidRep(exporterIFC, element, catId, exporterIFC.Get3DContextHandle("Body"), bodyItems, null);
                                            shapeReps.Add(shapeRep);
                                            IFCAnyHandleUtil.SetAttribute(repHnd, "Representations", shapeReps);

                                            // Allow support for up to 256 named IfcSlab components, as defined in IFCSubElementEnums.cs.
                                            string slabGUID = (loopNum < 256) ? GUIDUtil.CreateSubElementGUID(element, subElementStart + loopNum) : GUIDUtil.CreateGUID();

                                            IFCAnyHandle slabPlacement = ExporterUtil.CreateLocalPlacement(file, slabExtrusionCreationData.GetLocalPlacement(), null);
                                            IFCAnyHandle slabHnd       = IFCInstanceExporter.CreateSlab(exporterIFC, element, slabGUID, ownerHistory,
                                                                                                        slabPlacement, repHnd, subSlabType);
                                            IFCExportInfoPair exportType = new IFCExportInfoPair(IFCEntityType.IfcSlab, subSlabType);

                                            //slab quantities
                                            slabExtrusionCreationData.ScaledLength         = scaledExtrusionDepth;
                                            slabExtrusionCreationData.ScaledArea           = UnitUtil.ScaleArea(UnitUtil.ScaleArea(hostObjectSubcomponent.AreaOfCurveLoop));
                                            slabExtrusionCreationData.ScaledOuterPerimeter = UnitUtil.ScaleLength(curveLoops[0].GetExactLength());
                                            slabExtrusionCreationData.Slope = UnitUtil.ScaleAngle(MathUtil.SafeAcos(Math.Abs(slope)));

                                            IFCExportInfoPair slabRoofExportType = new IFCExportInfoPair(IFCEntityType.IfcSlab, slabRoofPredefinedType);
                                            productWrapper.AddElement(null, slabHnd, setter, slabExtrusionCreationData, false, slabRoofExportType);

                                            // Create type
                                            IFCAnyHandle slabRoofTypeHnd = ExporterUtil.CreateGenericTypeFromElement(element, slabRoofExportType, exporterIFC.GetFile(), ownerHistory, slabRoofPredefinedType, productWrapper);
                                            ExporterCacheManager.TypeRelationsCache.Add(slabRoofTypeHnd, slabHnd);

                                            elementHandles.Add(slabHnd);
                                            slabHandles.Add(slabHnd);

                                            hostObjectOpeningLoops.Add(slabCurveLoop);
                                            maximumScaledDepth = Math.Max(maximumScaledDepth, scaledDepth);
                                            loopNum++;

                                            ExporterUtil.AddIntoComplexPropertyCache(slabHnd, layersetInfo);

                                            // Create material association here
                                            if (layersetInfo != null && !IFCAnyHandleUtil.IsNullOrHasNoValue(layersetInfo.MaterialLayerSetHandle))
                                            {
                                                CategoryUtil.CreateMaterialAssociation(exporterIFC, slabHnd, layersetInfo.MaterialLayerSetHandle);
                                            }
                                        }
                                    }

                                    productWrapper.AddElement(element, hostObjectHandle, setter, extrusionCreationData, true, roofExportType);

                                    ExporterUtil.RelateObjects(exporterIFC, null, hostObjectHandle, slabHandles);

                                    OpeningUtil.AddOpeningsToElement(exporterIFC, elementHandles, hostObjectOpeningLoops, element, null, maximumScaledDepth,
                                                                     null, setter, localPlacement, productWrapper);


                                    transaction.Commit();
                                    return(hostObjectHandle);
                                }
                            }
                        }
                        catch
                        {
                            // SOmething wrong with the above process, unable to create the extrusion data. Reset any internal handles that may have been partially created since they are not committed
                            productWrapper.ClearInternalHandleWrapperData(element);
                            return(null);
                        }
                        finally
                        {
                            exporterIFC.ClearFaceWithElementHandleMap();
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Exports a generic family instance as IFC instance.
        /// </summary>
        /// <param name="type">The export type.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="familyInstance">The element.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        /// <param name="setter">The PlacementSetter.</param>
        /// <param name="extraParams">The extrusion creation data.</param>
        /// <param name="instanceGUID">The guid.</param>
        /// <param name="ownerHistory">The owner history handle.</param>
        /// <param name="instanceName">The name.</param>
        /// <param name="instanceDescription">The description.</param>
        /// <param name="instanceObjectType">The object type.</param>
        /// <param name="productRepresentation">The representation handle.</param>
        /// <param name="instanceTag">The tag for the entity, usually based on the element id.</param>
        /// <param name="ifcEnumType">The predefined type/shape type, if any, for the object.</param>
        /// <param name="overrideLocalPlacement">The local placement to use instead of the one in the placement setter, if appropriate.</param>
        /// <returns>The handle.</returns>
        public static IFCAnyHandle ExportGenericInstance(IFCExportType type,
                                                         ExporterIFC exporterIFC, Element familyInstance,
                                                         ProductWrapper wrapper, PlacementSetter setter, IFCExtrusionCreationData extraParams,
                                                         string instanceGUID, IFCAnyHandle ownerHistory,
                                                         string instanceName, string instanceDescription, string instanceObjectType,
                                                         IFCAnyHandle productRepresentation,
                                                         string instanceTag, string ifcEnumType, IFCAnyHandle overrideLocalPlacement)
        {
            IFCFile  file = exporterIFC.GetFile();
            Document doc  = familyInstance.Document;

            bool isRoomRelated      = IsRoomRelated(type);
            bool isChildInContainer = familyInstance.AssemblyInstanceId != ElementId.InvalidElementId;

            IFCAnyHandle localPlacementToUse = setter.LocalPlacement;
            ElementId    roomId = ElementId.InvalidElementId;

            if (isRoomRelated)
            {
                roomId = setter.UpdateRoomRelativeCoordinates(familyInstance, out localPlacementToUse);
            }

            //should remove the create method where there is no use of this handle for API methods
            //some places uses the return value of ExportGenericInstance as input parameter for API methods
            IFCAnyHandle instanceHandle = null;

            switch (type)
            {
            case IFCExportType.IfcBeam:
            case IFCExportType.IfcBeamType:
            {
                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "BEAM" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreateBeam(file, instanceGUID, ownerHistory,
                                                                instanceName, instanceDescription, instanceObjectType, localPlacementToUse,
                                                                productRepresentation, instanceTag, preDefinedType);
                break;
            }

            case IFCExportType.IfcColumn:
            case IFCExportType.IfcColumnType:
            {
                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "COLUMN" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreateColumn(file, instanceGUID, ownerHistory,
                                                                  instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag, preDefinedType);
                break;
            }

            case IFCExportType.IfcCurtainWall:
            case IFCExportType.IfcCurtainWallType:
            {
                instanceHandle = IFCInstanceExporter.CreateCurtainWall(file, instanceGUID, ownerHistory,
                                                                       instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                break;
            }

            case IFCExportType.IfcMember:
            case IFCExportType.IfcMemberType:
            {
                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "BRACE" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreateMember(file, instanceGUID, ownerHistory,
                                                                  instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag, preDefinedType);

                // Register the members's IFC handle for later use by truss export.
                ExporterCacheManager.ElementToHandleCache.Register(familyInstance.Id, instanceHandle);
                break;
            }

            case IFCExportType.IfcPlate:
            case IFCExportType.IfcPlateType:
            {
                IFCAnyHandle localPlacement = localPlacementToUse;
                if (overrideLocalPlacement != null)
                {
                    isChildInContainer = true;
                    localPlacement     = overrideLocalPlacement;
                }

                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "NOTDEFINED" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreatePlate(file, instanceGUID, ownerHistory,
                                                                 instanceName, instanceDescription, instanceObjectType, localPlacement, productRepresentation, instanceTag, preDefinedType);
                break;
            }

            case IFCExportType.IfcDiscreteAccessoryType:
            {
                instanceHandle = IFCInstanceExporter.CreateDiscreteAccessory(file, instanceGUID, ownerHistory,
                                                                             instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                break;
            }

            case IFCExportType.IfcDistributionControlElement:
            {
                instanceHandle = IFCInstanceExporter.CreateDistributionControlElement(file, instanceGUID, ownerHistory,
                                                                                      instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                                                                                      null);
                break;
            }

            case IFCExportType.IfcDistributionFlowElement:
            {
                instanceHandle = IFCInstanceExporter.CreateDistributionFlowElement(file, instanceGUID, ownerHistory,
                                                                                   instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                break;
            }

            case IFCExportType.IfcDistributionChamberElement:
            case IFCExportType.IfcDistributionChamberElementType:
            {
                instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(Common.Enums.IFCEntityType.IfcDistributionChamberElement, file, instanceGUID, ownerHistory,
                                                                            instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                break;
            }

            case IFCExportType.IfcFastenerType:
            {
                instanceHandle = IFCInstanceExporter.CreateFastener(file, instanceGUID, ownerHistory,
                                                                    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                break;
            }

            case IFCExportType.IfcMechanicalFastenerType:
            {
                double?nominalDiameter = null;
                double?nominalLength   = null;

                double nominalDiameterVal, nominalLengthVal;
                if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalDiameter", out nominalDiameterVal) != null)
                {
                    nominalDiameter = UnitUtil.ScaleLength(nominalDiameterVal);
                }
                if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalLength", out nominalLengthVal) != null)
                {
                    nominalLength = UnitUtil.ScaleLength(nominalLengthVal);
                }

                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "NOTDEFINED" : ifcEnumType;

                instanceHandle = IFCInstanceExporter.CreateMechanicalFastener(file, instanceGUID, ownerHistory,
                                                                              instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                                                                              nominalDiameter, nominalLength, preDefinedType);
                break;
            }

            case IFCExportType.IfcRailingType:
            {
                string        strEnumType;
                IFCExportType exportAs = ExporterUtil.GetExportType(exporterIFC, familyInstance, out strEnumType);
                if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                {
                    instanceHandle = IFCInstanceExporter.CreateRailing(file, instanceGUID, ownerHistory, instanceName, instanceDescription,
                                                                       instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                                                                       GetPreDefinedType <Toolkit.IFC4.IFCRailingType>(familyInstance, strEnumType).ToString());
                }
                else
                {
                    instanceHandle = IFCInstanceExporter.CreateRailing(file, instanceGUID, ownerHistory, instanceName, instanceDescription,
                                                                       instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                                                                       GetPreDefinedType <Toolkit.IFCRailingType>(familyInstance, strEnumType).ToString());
                }
                break;
            }

            case IFCExportType.IfcSpace:
            {
                string instanceLongName = NamingUtil.GetLongNameOverride(familyInstance, NamingUtil.GetLongNameOverride(familyInstance, instanceName));
                IFCInternalOrExternal internalOrExternal = CategoryUtil.IsElementExternal(familyInstance) ? IFCInternalOrExternal.External : IFCInternalOrExternal.Internal;

                instanceHandle = IFCInstanceExporter.CreateSpace(file, instanceGUID, ownerHistory, instanceName, instanceDescription,
                                                                 instanceObjectType, localPlacementToUse, productRepresentation, instanceLongName, IFCElementComposition.Element,
                                                                 internalOrExternal, null);
                break;
            }

            default:
            {
                if (ExporterCacheManager.ExportOptionsCache.ExportAs4 &&
                    (type == IFCExportType.IfcDistributionElement ||
                     type == IFCExportType.IfcEnergyConversionDevice ||
                     type == IFCExportType.IfcFlowController ||
                     type == IFCExportType.IfcFlowFitting ||
                     type == IFCExportType.IfcFlowMovingDevice ||
                     type == IFCExportType.IfcFlowSegment ||
                     type == IFCExportType.IfcFlowStorageDevice ||
                     type == IFCExportType.IfcFlowTerminal ||
                     type == IFCExportType.IfcFlowTreatmentDevice))
                {
                    // for IFC4, there are several entities that are valid in IFC2x3 but now have been made abstract or deprecated, so cannot be created. Create proxy instead.
                    //instanceHandle = IFCInstanceExporter.CreateBuildingElementProxy(file, instanceGUID, ownerHistory,
                    //    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                    //    Toolkit.IFC4.IFCBuildingElementProxyType.USERDEFINED.ToString());
                    Common.Enums.IFCEntityType exportEntity = Common.Enums.IFCEntityType.UnKnown;
                    if (Enum.TryParse(type.ToString(), out exportEntity))
                    {
                        instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportEntity, file, instanceGUID, ownerHistory,
                                                                                    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                    }
                }
                else if ((type == IFCExportType.IfcPile) ||
                         (type == IFCExportType.IfcFurnishingElement) || IsFurnishingElementSubType(type) ||
                         (type == IFCExportType.IfcEnergyConversionDevice) || IsEnergyConversionDeviceSubType(type) ||
                         (type == IFCExportType.IfcFlowFitting) || IsFlowFittingSubType(type) ||
                         (type == IFCExportType.IfcFlowMovingDevice) || IsFlowMovingDeviceSubType(type) ||
                         (type == IFCExportType.IfcFlowSegment) || IsFlowSegmentSubType(type) ||
                         (type == IFCExportType.IfcFlowStorageDevice) || IsFlowStorageDeviceSubType(type) ||
                         (type == IFCExportType.IfcFlowTerminal) || IsFlowTerminalSubType(type) ||
                         (type == IFCExportType.IfcFlowTreatmentDevice) || IsFlowTreatmentDeviceSubType(type) ||
                         (type == IFCExportType.IfcFlowController) || IsFlowControllerSubType(type) ||
                         (type == IFCExportType.IfcDistributionFlowElement) || IsDistributionFlowElementSubType(type) ||
                         (type == IFCExportType.IfcDistributionControlElement) || IsDistributionControlElementSubType(type) ||
                         (type == IFCExportType.IfcBuildingElementProxy) || (type == IFCExportType.IfcBuildingElementProxyType))
                {
                    string exportEntityStr = type.ToString();
                    Common.Enums.IFCEntityType exportEntity = Common.Enums.IFCEntityType.UnKnown;

                    if (String.Compare(exportEntityStr.Substring(exportEntityStr.Length - 4), "Type", true) == 0)
                    {
                        exportEntityStr = exportEntityStr.Substring(0, (exportEntityStr.Length - 4));
                    }
                    if (!Enum.TryParse(exportEntityStr, out exportEntity))
                    {
                        // This is a special case.   IFC2x3 has IfcFlowElement for the instance, and both IfcElectricHeaterType and IfcSpaceHeaterType.
                        // IFC4 has IfcSpaceHeater and IfcSpaceHeaterType.
                        // Since IfcElectricHeater doesn't exist in IFC4, TryParse will fail.  For the instance only, we will map it to IfcSpaceHeater,
                        // which will in turn be redirected to IfcFlowElement for IFC2x3, if necessary.
                        if (type == IFCExportType.IfcElectricHeaterType)
                        {
                            exportEntity = Common.Enums.IFCEntityType.IfcSpaceHeater;
                        }
                        else
                        {
                            exportEntity = Common.Enums.IFCEntityType.UnKnown;
                        }
                    }

                    if (exportEntity != Common.Enums.IFCEntityType.UnKnown)
                    {
                        instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportEntity, file, instanceGUID, ownerHistory,
                                                                                    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                    }
                }
                break;
            }
            }

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle))
            {
                bool containedInSpace = (roomId != ElementId.InvalidElementId);
                bool associateToLevel = containedInSpace ? false : !isChildInContainer;
                wrapper.AddElement(familyInstance, instanceHandle, setter, extraParams, associateToLevel);
                if (containedInSpace)
                {
                    ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, instanceHandle);
                }
            }
            return(instanceHandle);
        }
Esempio n. 26
0
        /// <summary>
        /// Exports an element as an IFC assembly.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportAssemblyInstanceElement(ExporterIFC exporterIFC, AssemblyInstance element,
                                                         ProductWrapper productWrapper)
        {
            if (element == null)
            {
                return(false);
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                IFCAnyHandle assemblyInstanceHnd = null;

                string          guid            = GUIDUtil.CreateGUID(element);
                IFCAnyHandle    ownerHistory    = exporterIFC.GetOwnerHistoryHandle();
                string          name            = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                string          description     = NamingUtil.GetDescriptionOverride(element, null);
                string          objectType      = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                IFCAnyHandle    localPlacement  = null;
                PlacementSetter placementSetter = null;
                IFCLevelInfo    levelInfo       = null;

                string        ifcEnumType;
                IFCExportType exportAs = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);
                if (exportAs == IFCExportType.IfcSystem)
                {
                    assemblyInstanceHnd = IFCInstanceExporter.CreateSystem(file, guid,
                                                                           ownerHistory, name, description, objectType);

                    // Create classification reference when System has classification filed name assigned to it
                    ClassificationUtil.CreateClassification(exporterIFC, file, element, assemblyInstanceHnd);

                    HashSet <IFCAnyHandle> relatedBuildings = new HashSet <IFCAnyHandle>();
                    relatedBuildings.Add(ExporterCacheManager.BuildingHandle);

                    IFCAnyHandle relServicesBuildings = IFCInstanceExporter.CreateRelServicesBuildings(file, GUIDUtil.CreateGUID(),
                                                                                                       exporterIFC.GetOwnerHistoryHandle(), null, null, assemblyInstanceHnd, relatedBuildings);
                }
                else
                {
                    using (placementSetter = PlacementSetter.Create(exporterIFC, element))
                    {
                        string       elementTag     = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));
                        IFCAnyHandle representation = null;

                        // We have limited support for exporting assemblies as other container types.
                        localPlacement = placementSetter.LocalPlacement;
                        levelInfo      = placementSetter.LevelInfo;
                        ifcEnumType    = IFCValidateEntry.GetValidIFCType(element, ifcEnumType);

                        switch (exportAs)
                        {
                        case IFCExportType.IfcCurtainWall:
                            assemblyInstanceHnd = IFCInstanceExporter.CreateCurtainWall(file, guid,
                                                                                        ownerHistory, name, description, objectType, localPlacement, representation, elementTag);
                            break;

                        case IFCExportType.IfcRamp:
                            string rampPredefinedType = RampExporter.GetIFCRampType(ifcEnumType);
                            assemblyInstanceHnd = IFCInstanceExporter.CreateRamp(file, guid,
                                                                                 ownerHistory, name, description, objectType, localPlacement, representation, elementTag,
                                                                                 rampPredefinedType);
                            break;

                        case IFCExportType.IfcRoof:
                            assemblyInstanceHnd = IFCInstanceExporter.CreateRoof(file, guid,
                                                                                 ownerHistory, name, description, objectType, localPlacement, representation, elementTag,
                                                                                 ifcEnumType);
                            break;

                        case IFCExportType.IfcStair:
                            string stairPredefinedType = StairsExporter.GetIFCStairType(ifcEnumType);
                            assemblyInstanceHnd = IFCInstanceExporter.CreateStair(file, guid,
                                                                                  ownerHistory, name, description, objectType, localPlacement, representation, elementTag,
                                                                                  stairPredefinedType);
                            break;

                        case IFCExportType.IfcWall:
                            assemblyInstanceHnd = IFCInstanceExporter.CreateWall(file, guid,
                                                                                 ownerHistory, name, description, objectType, localPlacement, representation, elementTag,
                                                                                 ifcEnumType);
                            break;

                        default:
                            IFCElementAssemblyType assemblyPredefinedType = GetPredefinedTypeFromObjectType(objectType);
                            assemblyInstanceHnd = IFCInstanceExporter.CreateElementAssembly(file, guid,
                                                                                            ownerHistory, name, description, objectType, localPlacement, representation, elementTag,
                                                                                            IFCAssemblyPlace.NotDefined, assemblyPredefinedType);
                            break;
                        }
                    }
                }

                if (assemblyInstanceHnd == null)
                {
                    return(false);
                }

                bool relateToLevel = (levelInfo != null);
                productWrapper.AddElement(element, assemblyInstanceHnd, levelInfo, null, relateToLevel);

                ExporterCacheManager.AssemblyInstanceCache.RegisterAssemblyInstance(element.Id, assemblyInstanceHnd);

                tr.Commit();
                return(true);
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Exports a MEP family instance.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                string        ifcEnumType;
                IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);

                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    IFCAnyHandle localPlacementToUse = setter.GetPlacement();
                    using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                    {
                        ElementId catId = CategoryUtil.GetSafeCategoryId(element);

                        BodyExporterOptions bodyExporterOptions   = new BodyExporterOptions(true);
                        IFCAnyHandle        productRepresentation = RepresentationUtil.CreateBRepProductDefinitionShape(element.Document.Application,
                                                                                                                        exporterIFC, element, catId, geometryElement, bodyExporterOptions, null, extraParams);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(productRepresentation))
                        {
                            extraParams.ClearOpenings();
                            return;
                        }

                        IFCAnyHandle   ownerHistory    = exporterIFC.GetOwnerHistoryHandle();
                        ElementId      typeId          = element.GetTypeId();
                        ElementType    type            = element.Document.GetElement(typeId) as ElementType;
                        FamilyTypeInfo currentTypeInfo = ExporterCacheManager.TypeObjectsCache.Find(typeId, false);

                        bool found = currentTypeInfo.IsValid();
                        if (!found)
                        {
                            string typeGUID            = ExporterIFCUtils.CreateGUID(type);
                            string origTypeName        = exporterIFC.GetName();
                            string typeName            = NamingUtil.GetNameOverride(type, origTypeName);
                            string typeObjectType      = NamingUtil.CreateIFCObjectName(exporterIFC, type);
                            string applicableOccurance = NamingUtil.GetObjectTypeOverride(type, typeObjectType);
                            string typeDescription     = NamingUtil.GetDescriptionOverride(type, null);
                            string typeElemId          = NamingUtil.CreateIFCElementId(type);

                            HashSet <IFCAnyHandle> propertySetsOpt = new HashSet <IFCAnyHandle>();
                            IList <IFCAnyHandle>   repMapListOpt   = new List <IFCAnyHandle>();

                            IFCAnyHandle styleHandle = FamilyExporterUtil.ExportGenericType(file, exportType, ifcEnumType, typeGUID, ownerHistory, typeName,
                                                                                            typeDescription, applicableOccurance, propertySetsOpt, repMapListOpt, typeElemId, typeName, element, type);
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
                            {
                                currentTypeInfo.Style = styleHandle;
                                ExporterCacheManager.TypeObjectsCache.Register(typeId, false, currentTypeInfo);
                            }
                        }
                        string instanceGUID        = ExporterIFCUtils.CreateGUID(element);
                        string origInstanceName    = exporterIFC.GetName();
                        string instanceName        = NamingUtil.GetNameOverride(element, origInstanceName);
                        string objectType          = NamingUtil.CreateIFCObjectName(exporterIFC, element);
                        string instanceObjectType  = NamingUtil.GetObjectTypeOverride(element, objectType);
                        string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceElemId      = NamingUtil.CreateIFCElementId(element);

                        bool roomRelated = !FamilyExporterUtil.IsDistributionFlowElementSubType(exportType);

                        ElementId roomId = ElementId.InvalidElementId;
                        if (roomRelated)
                        {
                            roomId = setter.UpdateRoomRelativeCoordinates(element, out localPlacementToUse);
                        }

                        IFCAnyHandle instanceHandle = null;
                        if (FamilyExporterUtil.IsFurnishingElementSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFurnishingElement(file, instanceGUID, ownerHistory,
                                                                                         instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (FamilyExporterUtil.IsDistributionFlowElementSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateDistributionFlowElement(file, instanceGUID, ownerHistory,
                                                                                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (FamilyExporterUtil.IsEnergyConversionDeviceSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateEnergyConversionDevice(file, instanceGUID, ownerHistory,
                                                                                              instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (FamilyExporterUtil.IsFlowFittingSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowFitting(file, instanceGUID, ownerHistory,
                                                                                   instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (FamilyExporterUtil.IsFlowMovingDeviceSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowMovingDevice(file, instanceGUID, ownerHistory,
                                                                                        instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (FamilyExporterUtil.IsFlowSegmentSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowSegment(file, instanceGUID, ownerHistory,
                                                                                   instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (FamilyExporterUtil.IsFlowStorageDeviceSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowStorageDevice(file, instanceGUID, ownerHistory,
                                                                                         instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (FamilyExporterUtil.IsFlowTerminalSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowTerminal(file, instanceGUID, ownerHistory,
                                                                                    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (FamilyExporterUtil.IsFlowTreatmentDeviceSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowTreatmentDevice(file, instanceGUID, ownerHistory,
                                                                                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (FamilyExporterUtil.IsFlowControllerSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowController(file, instanceGUID, ownerHistory,
                                                                                      instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }

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

                        if (roomId != ElementId.InvalidElementId)
                        {
                            exporterIFC.RelateSpatialElement(roomId, instanceHandle);
                            productWrapper.AddElement(instanceHandle, setter, extraParams, false);
                        }
                        else
                        {
                            productWrapper.AddElement(instanceHandle, setter, extraParams, LevelUtil.AssociateElementToLevel(element));
                        }

                        OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, element, extraParams, exporterIFC, localPlacementToUse, setter, productWrapper);

                        if (currentTypeInfo.IsValid())
                        {
                            ExporterCacheManager.TypeRelationsCache.Add(currentTypeInfo.Style, instanceHandle);
                        }

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);

                        ExporterCacheManager.MEPCache.Register(element, instanceHandle);

                        tr.Commit();
                    }
                }
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Exports a Rebar to IFC ReinforcingBar.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element to be exported.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>The list of IfcReinforcingBar handles created.</returns>
        public static ISet <IFCAnyHandle> ExportRebar(ExporterIFC exporterIFC, Element element, ProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();
            HashSet <IFCAnyHandle> createdRebars = new HashSet <IFCAnyHandle>();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element))
                {
                    if (element is Rebar)
                    {
                        GeometryElement rebarGeometry = ExporterIFCUtils.GetRebarGeometry(element as Rebar, ExporterCacheManager.ExportOptionsCache.FilterViewForExport);

                        // only options are: Not Export, BuildingElementProxy, or ReinforcingBar/Mesh, depending on layout.
                        // Not Export is handled previously, and ReinforcingBar vs Mesh will be determined below.
                        string        ifcEnumType;
                        IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);

                        if (exportType == IFCExportType.IfcBuildingElementProxy ||
                            exportType == IFCExportType.IfcBuildingElementProxyType)
                        {
                            if (rebarGeometry != null)
                            {
                                ProxyElementExporter.ExportBuildingElementProxy(exporterIFC, element, rebarGeometry, productWrapper);
                                transaction.Commit();
                            }
                            return(null);
                        }
                    }

                    IFCAnyHandle prodRep = null;

                    double totalBarLengthUnscale = GetRebarTotalLength(element);
                    double volumeUnscale         = GetRebarVolume(element);
                    double totalBarLength        = UnitUtil.ScaleLength(totalBarLengthUnscale);

                    if (MathUtil.IsAlmostZero(totalBarLength))
                    {
                        return(null);
                    }

                    ElementId materialId = ElementId.InvalidElementId;
                    ParameterUtil.GetElementIdValueFromElementOrSymbol(element, BuiltInParameter.MATERIAL_ID_PARAM, out materialId);

                    Document     doc         = element.Document;
                    ElementId    typeId      = element.GetTypeId();
                    RebarBarType elementType = doc.GetElement(element.GetTypeId()) as RebarBarType;
                    double       diameter    = UnitUtil.ScaleLength(elementType == null ? 1.0 / 12.0 : elementType.BarDiameter);
                    double       radius      = diameter / 2.0;
                    double       longitudinalBarNominalDiameter  = diameter;
                    double       longitudinalBarCrossSectionArea = UnitUtil.ScaleArea(volumeUnscale / totalBarLengthUnscale);
                    double       barLength = totalBarLength / GetRebarQuantity(element);

                    IList <Curve> baseCurves           = GetRebarCenterlineCurves(element, true, false, false);
                    int           numberOfBarPositions = GetNumberOfBarPositions(element);

                    string steelGrade = NamingUtil.GetOverrideStringValue(element, "SteelGrade", null);

                    // Allow use of IFC2x3 or IFC4 naming.
                    string predefinedType = NamingUtil.GetOverrideStringValue(element, "BarRole", null);
                    if (string.IsNullOrWhiteSpace(predefinedType))
                    {
                        predefinedType = NamingUtil.GetOverrideStringValue(element, "PredefinedType", null);
                    }
                    IFCReinforcingBarRole role = GetReinforcingBarRole(predefinedType);

                    string origRebarName    = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                    string rebarDescription = NamingUtil.GetDescriptionOverride(element, null);
                    string rebarObjectType  = NamingUtil.GetObjectTypeOverride(element, NamingUtil.CreateIFCObjectName(exporterIFC, element));
                    string rebarTag         = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));

                    const int maxBarGUIDS = IFCReinforcingBarSubElements.BarEnd - IFCReinforcingBarSubElements.BarStart + 1;
                    ElementId categoryId  = CategoryUtil.GetSafeCategoryId(element);

                    IFCAnyHandle originalPlacement = setter.LocalPlacement;

                    for (int i = 0; i < numberOfBarPositions; i++)
                    {
                        if (!DoesBarExistAtPosition(element, i))
                        {
                            continue;
                        }

                        string rebarName = NamingUtil.GetNameOverride(element, origRebarName + ": " + i);

                        Transform barTrf = GetBarPositionTransform(element, i);

                        IList <Curve> curves   = new List <Curve>();
                        double        endParam = 0.0;
                        foreach (Curve baseCurve in baseCurves)
                        {
                            if (baseCurve is Arc || baseCurve is Ellipse)
                            {
                                if (baseCurve.IsBound)
                                {
                                    endParam += UnitUtil.ScaleAngle(baseCurve.GetEndParameter(1) - baseCurve.GetEndParameter(0));
                                }
                                else
                                {
                                    endParam += UnitUtil.ScaleAngle(2 * Math.PI);
                                }
                            }
                            else
                            {
                                endParam += 1.0;
                            }
                            curves.Add(baseCurve.CreateTransformed(barTrf));
                        }

                        IFCAnyHandle           compositeCurve = GeometryUtil.CreateCompositeCurve(exporterIFC, curves);
                        IFCAnyHandle           sweptDiskSolid = IFCInstanceExporter.CreateSweptDiskSolid(file, compositeCurve, radius, null, 0, endParam);
                        HashSet <IFCAnyHandle> bodyItems      = new HashSet <IFCAnyHandle>();
                        bodyItems.Add(sweptDiskSolid);

                        IFCAnyHandle         shapeRep  = RepresentationUtil.CreateAdvancedSweptSolidRep(exporterIFC, element, categoryId, exporterIFC.Get3DContextHandle("Body"), bodyItems, null);
                        IList <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>();
                        shapeReps.Add(shapeRep);
                        prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);

                        IFCAnyHandle copyLevelPlacement = (i == 0) ? originalPlacement : ExporterUtil.CopyLocalPlacement(file, originalPlacement);

                        string rebarGUID = (i < maxBarGUIDS) ?
                                           GUIDUtil.CreateSubElementGUID(element, i + (int)IFCReinforcingBarSubElements.BarStart) :
                                           GUIDUtil.CreateGUID();
                        IFCAnyHandle elemHnd = IFCInstanceExporter.CreateReinforcingBar(file, rebarGUID, exporterIFC.GetOwnerHistoryHandle(),
                                                                                        rebarName, rebarDescription, rebarObjectType, copyLevelPlacement,
                                                                                        prodRep, rebarTag, steelGrade, longitudinalBarNominalDiameter, longitudinalBarCrossSectionArea,
                                                                                        barLength, role, null);
                        createdRebars.Add(elemHnd);

                        productWrapper.AddElement(element, elemHnd, setter.LevelInfo, null, true);
                        ExporterCacheManager.HandleToElementCache.Register(elemHnd, element.Id);

                        CategoryUtil.CreateMaterialAssociation(exporterIFC, elemHnd, materialId);
                    }
                }
                transaction.Commit();
            }
            return(createdRebars);
        }
Esempio n. 29
0
        /// <summary>
        /// Adds openings to an element.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="elementHandles">The parent handles.</param>
        /// <param name="curveLoops">The parent CurveLoops.</param>
        /// <param name="element">The element.</param>
        /// <param name="lcs">The local coordinate system.</param>
        /// <param name="scaledWidth">The width.</param>
        /// <param name="range">The range.</param>
        /// <param name="setter">The placement setter.</param>
        /// <param name="localPlacement">The local placement.</param>
        /// <param name="localWrapper">The wrapper.</param>
        public static void AddOpeningsToElement(ExporterIFC exporterIFC, IList<IFCAnyHandle> elementHandles,
            IList<CurveLoop> curveLoops, Element element, Transform lcs, double scaledWidth,
            IFCRange range, PlacementSetter setter, IFCAnyHandle localPlacement, ProductWrapper localWrapper)
        {
            IList<IFCOpeningData> openingDataList = ExporterIFCUtils.GetOpeningData(exporterIFC, element, lcs, range);
             IFCFile file = exporterIFC.GetFile();
             IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
             foreach (IFCOpeningData openingData in openingDataList)
             {
            Element openingElem = element.Document.GetElement(openingData.OpeningElementId);
            if (openingElem == null)
               openingElem = element;

            bool currentWallIsHost = false;
            FamilyInstance openingFInst = openingElem as FamilyInstance;
            if (openingFInst != null && openingFInst.Host != null)
            {
               if (openingFInst.Host.Id == element.Id)
                  currentWallIsHost = true;
                  //continue;      // If the host is not the current Wall, skip this opening
            }

            // Don't export the opening if WallSweep category has been turned off.
            // This is currently restricted to WallSweeps because the element responsible for the opening could be a variety of things,
            // including a line as part of the elevation profile of the wall.
            // As such, we will restrict which element types we check for CanExportElement.
            if ((openingElem is WallSweep) && (!ElementFilteringUtil.CanExportElement(exporterIFC, openingElem, true)))
               continue;

            IList<IFCExtrusionData> extrusionDataList = openingData.GetExtrusionData();
            IFCAnyHandle parentHandle = null;
            if (elementHandles.Count > 1 && extrusionDataList.Count > 0)
            {
               parentHandle = FindParentHandle(elementHandles, curveLoops, extrusionDataList[0].GetLoops()[0]);
            }

            if (parentHandle == null)
               parentHandle = elementHandles[0];

            bool isDoorOrWindowOpening = IsDoorOrWindowOpening(exporterIFC, openingElem, element);
            bool insertHasHost = false;
            bool insertInThisHost = false;
            if (openingElem is FamilyInstance && element is Wall)
            {
               string ifcEnumType;
               IFCExportInfoPair exportType = ExporterUtil.GetExportType(exporterIFC, openingElem, out ifcEnumType);
               Element instHost = (openingElem as FamilyInstance).Host;
               insertHasHost = (instHost != null);
               insertInThisHost = (insertHasHost && instHost.Id == element.Id);
               isDoorOrWindowOpening =
                  insertInThisHost &&
                  (exportType.ExportInstance == IFCEntityType.IfcDoor ||
                  exportType.ExportType == IFCEntityType.IfcDoorType ||
                  exportType.ExportInstance == IFCEntityType.IfcWindow ||
                  exportType.ExportType == IFCEntityType.IfcWindowType);
            }

            if (isDoorOrWindowOpening && currentWallIsHost)
            {
               DoorWindowDelayedOpeningCreator delayedCreator =
                   DoorWindowDelayedOpeningCreator.Create(exporterIFC, openingData, scaledWidth, element.Id, parentHandle, setter.LevelId);
               if (delayedCreator != null)
               {
                  ExporterCacheManager.DoorWindowDelayedOpeningCreatorCache.Add(delayedCreator);
                  continue;
               }
            }

            // If the opening is "filled" by another element (either a door or window as
            // determined above, or an embedded wall, then we can't use the element GUID
            // for the opening.
            bool canUseElementGUID = (!insertHasHost || insertInThisHost) &&
               !isDoorOrWindowOpening &&
               !(openingElem is Wall);

            IList<Solid> solids = openingData.GetOpeningSolids();
            foreach (Solid solid in solids)
            {
               using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData())
               {
                  extrusionCreationData.SetLocalPlacement(ExporterUtil.CreateLocalPlacement(file, localPlacement, null));
                  extrusionCreationData.ReuseLocalPlacement = true;

                  string openingGUID = CreateOpeningGUID(openingElem, canUseElementGUID);
                  canUseElementGUID = false; // Either it was used above, and therefore is now false, or it was already false.

                  CreateOpening(exporterIFC, parentHandle, element, openingElem, openingGUID, solid, scaledWidth, openingData.IsRecess, extrusionCreationData,
                      setter, localWrapper);
               }
            }

            foreach (IFCExtrusionData extrusionData in extrusionDataList)
            {
               if (extrusionData.ScaledExtrusionLength < MathUtil.Eps())
                  extrusionData.ScaledExtrusionLength = scaledWidth;

               string openingGUID = CreateOpeningGUID(openingElem, canUseElementGUID);
               canUseElementGUID = false; // Either it was used above, and therefore is now false, or it was already false.

               CreateOpening(exporterIFC, parentHandle, localPlacement, element, openingElem, openingGUID, extrusionData, lcs, openingData.IsRecess,
                   setter, localWrapper);
            }
             }
        }
Esempio n. 30
0
        /// <summary>
        /// Exports a Rebar to IFC ReinforcingMesh.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="element">
        /// The element to be exported.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportRebar(ExporterIFC exporterIFC,
                                       Rebar element, Autodesk.Revit.DB.View filterView, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    GeometryElement rebarGeometry = ExporterIFCUtils.GetRebarGeometry(element, filterView);

                    // only options are: Not Export, BuildingElementProxy, or ReinforcingBar/Mesh, depending on layout.
                    // Not Export is handled previously, and ReinforcingBar vs Mesh will be determined below.
                    string        ifcEnumType;
                    IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType);

                    if (exportType == IFCExportType.ExportBuildingElementProxy)
                    {
                        if (rebarGeometry != null)
                        {
                            ProxyElementExporter.ExportBuildingElementProxy(exporterIFC, element, rebarGeometry, productWrapper);
                            transaction.Commit();
                        }
                        return;
                    }

                    IFCAnyHandle prodRep = null;
                    using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData())
                    {
                        extrusionCreationData.SetLocalPlacement(setter.GetPlacement());

                        if (rebarGeometry != null)
                        {
                            ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

                            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                            prodRep = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, categoryId, rebarGeometry, bodyExporterOptions,
                                                              extrusionCreationData).RepresentationHnd;
                            if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodRep))
                            {
                                extrusionCreationData.ClearOpenings();
                            }
                        }

                        double scale = exporterIFC.LinearScale;

                        double barLength = element.TotalLength * scale;
                        if (MathUtil.IsAlmostZero(barLength))
                        {
                            return;
                        }

                        int quantity = element.Quantity;
                        if (quantity < 1)
                        {
                            return;
                        }

                        ElementId    typeId      = element.GetTypeId();
                        RebarBarType elementType = element.Document.GetElement(element.GetTypeId()) as RebarBarType;
                        double       diameter    = elementType == null ? 1.0 / 12.0 : elementType.BarDiameter;
                        double       longitudinalBarNominalDiameter  = diameter * scale;
                        double       longitudinalBarCrossSectionArea = (element.Volume * scale * scale * scale) / barLength;

                        string       steelGradeOpt = null;
                        IFCAnyHandle elemHnd       = null;

                        string rebarGUID        = ExporterIFCUtils.CreateGUID(element);
                        string origRebarName    = exporterIFC.GetName();
                        string rebarName        = NamingUtil.GetNameOverride(element, origRebarName);
                        string rebarDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string rebarObjectType  = NamingUtil.GetObjectTypeOverride(element, NamingUtil.CreateIFCObjectName(exporterIFC, element));
                        string rebarElemId      = NamingUtil.CreateIFCElementId(element);

                        if (element.LayoutRule == RebarLayoutRule.Single || (quantity == 1))
                        {
                            IFCReinforcingBarRole role = IFCReinforcingBarRole.NotDefined;
                            elemHnd = IFCInstanceExporter.CreateReinforcingBar(file, rebarGUID, exporterIFC.GetOwnerHistoryHandle(),
                                                                               rebarName, rebarDescription, rebarObjectType, extrusionCreationData.GetLocalPlacement(),
                                                                               prodRep, rebarElemId, steelGradeOpt, longitudinalBarNominalDiameter, longitudinalBarCrossSectionArea,
                                                                               barLength, role, null);
                        }
                        else
                        {
                            double meshLength;
                            double longitudinalBarSpacing;
                            double val = element.ArrayLength * scale;

                            if (element.LayoutRule == RebarLayoutRule.NumberWithSpacing)
                            {
                                longitudinalBarSpacing = val;
                                meshLength             = val * (quantity - 1);
                            }
                            else
                            {
                                meshLength             = val;
                                longitudinalBarSpacing = val / (quantity - 1);
                            }

                            double meshWidth = diameter * scale; // array is in one direction only.
                            double transverseBarNominalDiameter  = longitudinalBarNominalDiameter;
                            double transverseBarCrossSectionArea = longitudinalBarCrossSectionArea;
                            double transverseBarSpacing          = longitudinalBarSpacing;

                            elemHnd = IFCInstanceExporter.CreateReinforcingMesh(file, rebarGUID,
                                                                                exporterIFC.GetOwnerHistoryHandle(), rebarName,
                                                                                rebarDescription, rebarObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, rebarElemId,
                                                                                steelGradeOpt, meshLength, meshWidth, longitudinalBarNominalDiameter,
                                                                                transverseBarNominalDiameter, longitudinalBarCrossSectionArea,
                                                                                transverseBarCrossSectionArea, longitudinalBarSpacing,
                                                                                transverseBarSpacing);
                        }

                        productWrapper.AddElement(elemHnd, setter.GetLevelInfo(), extrusionCreationData, true);

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);
                    }
                }
                transaction.Commit();
            }
        }