Beispiel #1
0
        /// <summary>
        /// Add a generic element to the wrapper, with associated setter and extrusion data information, and create associated internal property sets if option is set.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handle">The element handle.</param>
        /// <param name="setter">The placement setter.</param>
        /// <param name="data">The extrusion creation data (can be null.)</param>
        /// <param name="relateToLevel">Relate to the level in the setter, or not.</param>
        public void AddElement(Element element, IFCAnyHandle handle, PlacementSetter setter, IFCExtrusionCreationData data, bool relateToLevel)
        {
            // There is a bug in the internal AddElement that requires us to do a levelInfo null check here.
            IFCLevelInfo levelInfo             = setter.LevelInfo;
            bool         actuallyRelateToLevel = relateToLevel && (levelInfo != null);

            m_InternalWrapper.AddElement(handle, levelInfo, data, actuallyRelateToLevel);
            if (levelInfo == null && relateToLevel)
            {
                ExporterCacheManager.LevelInfoCache.OrphanedElements.Add(handle);
            }
            RegisterHandleWithElement(element, handle);
        }
Beispiel #2
0
        /// <summary>
        /// Exports mullion.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="mullion">
        /// The mullion object.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="localPlacement">
        /// The local placement handle.
        /// </param>
        /// <param name="extraParams">
        /// The extrusion creation data.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, Mullion mullion, GeometryElement geometryElement,
                                  IFCAnyHandle localPlacement, IFCExtrusionCreationData extraParams, IFCPlacementSetter setter, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            ElementId catId = CategoryUtil.GetSafeCategoryId(mullion);

            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
            IFCAnyHandle        repHnd = RepresentationUtil.CreateBRepProductDefinitionShape(mullion.Document.Application, exporterIFC, mullion, catId,
                                                                                             geometryElement, bodyExporterOptions, null, extraParams);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd))
            {
                extraParams.ClearOpenings();
                return;
            }

            string       elemGUID       = ExporterIFCUtils.CreateGUID(mullion);
            IFCAnyHandle ownerHistory   = exporterIFC.GetOwnerHistoryHandle();
            string       elemObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, mullion);
            string       elemId         = NamingUtil.CreateIFCElementId(mullion);

            IFCAnyHandle mullionHnd = IFCInstanceExporter.CreateMember(file, elemGUID, ownerHistory, elemObjectType, null, elemObjectType,
                                                                       localPlacement, repHnd, elemId);

            productWrapper.AddElement(mullionHnd, setter, extraParams, LevelUtil.AssociateElementToLevel(mullion));

            PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, mullion, productWrapper);
        }
Beispiel #3
0
        /// <summary>
        /// Exports mullion.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="mullion">
        /// The mullion object.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="localPlacement">
        /// The local placement handle.
        /// </param>
        /// <param name="extraParams">
        /// The extrusion creation data.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, Mullion mullion, GeometryElement geometryElement,
           IFCAnyHandle localPlacement, IFCExtrusionCreationData extraParams, IFCPlacementSetter setter, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            ElementId catId = CategoryUtil.GetSafeCategoryId(mullion);

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

            string elemGUID = ExporterIFCUtils.CreateGUID(mullion);
            IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
            string elemObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, mullion);
            string elemId = NamingUtil.CreateIFCElementId(mullion);

            IFCAnyHandle mullionHnd = IFCInstanceExporter.CreateMember(file, elemGUID, ownerHistory, elemObjectType, null, elemObjectType,
               localPlacement, repHnd, elemId);
            productWrapper.AddElement(mullionHnd, setter, extraParams, LevelUtil.AssociateElementToLevel(mullion));

            PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, mullion, productWrapper);
        }
        /// <summary>
        /// Exports an element as an IFC assembly.
        /// </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>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportAssemblyInstanceElement(ExporterIFC exporterIFC, AssemblyInstance element,
            IFCProductWrapper productWrapper)
        {
            if (element == null)
                return false;

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    string guid = ExporterIFCUtils.CreateGUID(element);
                    IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                    string name = exporterIFC.GetName();
                    string objectType = exporterIFC.GetFamilyName();
                    IFCAnyHandle localPlacement = placementSetter.GetPlacement();
                    IFCAnyHandle representation = null;
                    string elementTag = NamingUtil.CreateIFCElementId(element);
                    IFCElementAssemblyType predefinedType = GetPredefinedTypeFromObjectType(objectType);

                    IFCAnyHandle assemblyInstanceHnd = IFCInstanceExporter.CreateElementAssembly(file, guid,
                        ownerHistory, name, null, objectType, localPlacement, representation, elementTag,
                        IFCAssemblyPlace.NotDefined, predefinedType);

                    productWrapper.AddElement(assemblyInstanceHnd, placementSetter.GetLevelInfo(), null, true);

                    PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);

                    ExporterCacheManager.AssemblyInstanceCache.RegisterAssemblyInstance(element.Id, assemblyInstanceHnd);
                }
                tr.Commit();
                return true;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Exports an element as IFC covering.
        /// </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 IFCProductWrapper.
        /// </param>
        public static void ExportCovering(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, string ifcEnumType, IFCProductWrapper productWrapper)
        {
            bool exportParts = PartExporter.CanExportParts(element);

            if (exportParts && !PartExporter.CanExportElementInPartExport(element, element.Level.Id, false))
            {
                return;
            }

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

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    IFCAnyHandle prodRep = exportParts ? null : RepresentationUtil.CreateSurfaceProductDefinitionShape(exporterIFC,
                                                                                                                       element, geomElem, false, false);

                    string instanceGUID                  = ExporterIFCUtils.CreateGUID(element);
                    string origInstanceName              = exporterIFC.GetName();
                    string instanceName                  = NamingUtil.GetNameOverride(element, origInstanceName);
                    string instanceDescription           = NamingUtil.GetDescriptionOverride(element, null);
                    string instanceObjectType            = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                    string instanceElemId                = NamingUtil.CreateIFCElementId(element);
                    Toolkit.IFCCoveringType coveringType = GetIFCCoveringType(element, ifcEnumType);

                    IFCAnyHandle covering = IFCInstanceExporter.CreateCovering(file, instanceGUID, exporterIFC.GetOwnerHistoryHandle(),
                                                                               instanceName, instanceDescription, instanceObjectType, setter.GetPlacement(), prodRep, instanceElemId, coveringType);

                    if (exportParts)
                    {
                        PartExporter.ExportHostPart(exporterIFC, element, covering, productWrapper, setter, setter.GetPlacement(), null);
                    }
                    productWrapper.AddElement(covering, setter, null, LevelUtil.AssociateElementToLevel(element));

                    Ceiling ceiling = element as Ceiling;
                    if (ceiling != null && !exportParts)
                    {
                        HostObjectExporter.ExportHostObjectMaterials(exporterIFC, ceiling, covering,
                                                                     geomElem, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3);
                    }

                    ExporterIFCUtils.CreateCoveringPropertySet(exporterIFC, element, productWrapper);
                    PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);
                }
                transaction.Commit();
            }
        }
Beispiel #6
0
        /// <summary>
        /// Exports an element as a covering of type insulation.
        /// </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>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportDuctLining(ExporterIFC exporterIFC, Element element,
                                            GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            if (element == null || geometryElement == null)
            {
                return(false);
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(placementSetter.GetPlacement());

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                        IFCAnyHandle        representation      = RepresentationUtil.CreateBRepProductDefinitionShape(element.Document.Application, exporterIFC, element,
                                                                                                                      categoryId, geometryElement, bodyExporterOptions, null, ecData);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation))
                        {
                            ecData.ClearOpenings();
                            return(false);
                        }

                        string       guid           = ExporterIFCUtils.CreateGUID(element);
                        IFCAnyHandle ownerHistory   = exporterIFC.GetOwnerHistoryHandle();
                        string       objectType     = exporterIFC.GetFamilyName();
                        IFCAnyHandle localPlacement = ecData.GetLocalPlacement();
                        string       elementTag     = NamingUtil.CreateIFCElementId(element);

                        IFCAnyHandle ductLining = IFCInstanceExporter.CreateCovering(file, guid,
                                                                                     ownerHistory, objectType, null, objectType, localPlacement, representation, elementTag, IFCCoveringType.Wrapping);

                        productWrapper.AddElement(ductLining, placementSetter.GetLevelInfo(), ecData, LevelUtil.AssociateElementToLevel(element));

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);
                    }
                }
                tr.Commit();
                return(true);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Exports an element as a covering of type insulation.
        /// </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>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportDuctLining(ExporterIFC exporterIFC, Element element,
            GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            if (element == null || geometryElement == null)
                return false;

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(placementSetter.GetPlacement());

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                        IFCAnyHandle representation = RepresentationUtil.CreateBRepProductDefinitionShape(element.Document.Application, exporterIFC, element,
                            categoryId, geometryElement, bodyExporterOptions, null, ecData);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation))
                        {
                            ecData.ClearOpenings();
                            return false;
                        }

                        string guid = ExporterIFCUtils.CreateGUID(element);
                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                        string objectType = exporterIFC.GetFamilyName();
                        IFCAnyHandle localPlacement = ecData.GetLocalPlacement();
                        string elementTag = NamingUtil.CreateIFCElementId(element);

                        IFCAnyHandle ductLining = IFCInstanceExporter.CreateCovering(file, guid,
                            ownerHistory, objectType, null, objectType, localPlacement, representation, elementTag, IFCCoveringType.Wrapping);

                        productWrapper.AddElement(ductLining, placementSetter.GetLevelInfo(), ecData, LevelUtil.AssociateElementToLevel(element));

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);
                    }
                }
                tr.Commit();
                return true;
            }
        }
Beispiel #8
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 IFCProductWrapper.</param>
        public static void ExportRoofAsParts(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    IFCAnyHandle ownerHistory   = exporterIFC.GetOwnerHistoryHandle();
                    IFCAnyHandle localPlacement = setter.GetPlacement();

                    using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData())
                    {
                        extrusionCreationData.SetLocalPlacement(setter.GetPlacement());
                        extrusionCreationData.PossibleExtrusionAxes = IFCExtrusionAxes.TryXY;

                        IFCAnyHandle prodRepHnd = null;

                        string elementGUID        = ExporterIFCUtils.CreateGUID(element);
                        string origElementName    = exporterIFC.GetName();
                        string elementName        = NamingUtil.GetNameOverride(element, origElementName);
                        string elementDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string elementObjectType  = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                        string elementId          = NamingUtil.CreateIFCElementId(element);

                        //need to convert the string to enum
                        string       ifcEnumType = CategoryUtil.GetIFCEnumTypeName(exporterIFC, element);
                        IFCAnyHandle roofHandle  = IFCInstanceExporter.CreateRoof(file, elementGUID, ownerHistory, elementName, elementDescription, elementObjectType, localPlacement, prodRepHnd, elementId, GetIFCRoofType(ifcEnumType));

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

                        productWrapper.AddElement(roofHandle, setter, extrusionCreationData, LevelUtil.AssociateElementToLevel(element));

                        OpeningUtil.CreateOpeningsIfNecessary(roofHandle, element, extrusionCreationData, exporterIFC, extrusionCreationData.GetLocalPlacement(), setter, productWrapper);

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);
                    }
                    transaction.Commit();
                }
            }
        }
Beispiel #9
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="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportAssemblyInstanceElement(ExporterIFC exporterIFC, AssemblyInstance element,
                                                         IFCProductWrapper productWrapper)
        {
            if (element == null)
            {
                return(false);
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    string                 guid           = ExporterIFCUtils.CreateGUID(element);
                    IFCAnyHandle           ownerHistory   = exporterIFC.GetOwnerHistoryHandle();
                    string                 name           = exporterIFC.GetName();
                    string                 objectType     = exporterIFC.GetFamilyName();
                    IFCAnyHandle           localPlacement = placementSetter.GetPlacement();
                    IFCAnyHandle           representation = null;
                    string                 elementTag     = NamingUtil.CreateIFCElementId(element);
                    IFCElementAssemblyType predefinedType = GetPredefinedTypeFromObjectType(objectType);

                    IFCAnyHandle assemblyInstanceHnd = IFCInstanceExporter.CreateElementAssembly(file, guid,
                                                                                                 ownerHistory, name, null, objectType, localPlacement, representation, elementTag,
                                                                                                 IFCAssemblyPlace.NotDefined, predefinedType);

                    productWrapper.AddElement(assemblyInstanceHnd, placementSetter.GetLevelInfo(), null, true);

                    PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);

                    ExporterCacheManager.AssemblyInstanceCache.RegisterAssemblyInstance(element.Id, assemblyInstanceHnd);
                }
                tr.Commit();
                return(true);
            }
        }
Beispiel #10
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();
                    }
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Exports a ramp to IfcRamp, without decomposing into separate runs and landings.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="ifcEnumType">The ramp type.</param>
        /// <param name="ramp">The ramp element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="numFlights">The number of flights for a multistory ramp.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportRamp(ExporterIFC exporterIFC, string ifcEnumType, Element ramp, GeometryElement geometryElement,
            int numFlights, IFCProductWrapper productWrapper)
        {
            if (ramp == null || geometryElement == null)
                return;

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, ramp))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(placementSetter.GetPlacement());

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(ramp);
                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions();
                        IFCAnyHandle representation = RepresentationUtil.CreateBRepProductDefinitionShape(ramp.Document.Application,
                            exporterIFC, ramp, categoryId, geometryElement, bodyExporterOptions, null, ecData);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation))
                        {
                            ecData.ClearOpenings();
                            return;
                        }

                        string containedRampGuid = ExporterIFCUtils.CreateSubElementGUID(ramp, (int)IFCRampSubElements.ContainedRamp);
                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                        string origRampName = exporterIFC.GetName();
                        string rampName = NamingUtil.GetNameOverride(ramp, origRampName);
                        string rampDescription = NamingUtil.GetDescriptionOverride(ramp, null);
                        string rampObjectType = NamingUtil.GetObjectTypeOverride(ramp, NamingUtil.CreateIFCObjectName(exporterIFC, ramp));
                        IFCAnyHandle containedRampLocalPlacement = ExporterUtil.CopyLocalPlacement(file, ecData.GetLocalPlacement());
                        string elementTag = NamingUtil.CreateIFCElementId(ramp);
                        IFCRampType rampType = GetIFCRampType(ifcEnumType);

                        List<IFCAnyHandle> components = new List<IFCAnyHandle>();
                        IFCAnyHandle containedRampHnd = IFCInstanceExporter.CreateRamp(file, containedRampGuid, ownerHistory, rampName,
                            rampDescription, rampObjectType, containedRampLocalPlacement, representation, elementTag, rampType);
                        components.Add(containedRampHnd);
                        productWrapper.AddElement(containedRampHnd, placementSetter.GetLevelInfo(), ecData, false);

                        string guid = ExporterIFCUtils.CreateGUID(ramp);
                        IFCAnyHandle localPlacement = ecData.GetLocalPlacement();

                        IFCAnyHandle rampHnd = IFCInstanceExporter.CreateRamp(file, guid, ownerHistory, rampName,
                            rampDescription, rampObjectType, localPlacement, null, elementTag, rampType);

                        productWrapper.AddElement(rampHnd, placementSetter.GetLevelInfo(), ecData, LevelUtil.AssociateElementToLevel(ramp));

                        StairRampContainerInfo stairRampInfo = new StairRampContainerInfo(rampHnd, components, null);
                        ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(ramp.Id, stairRampInfo);

                        ExportMultistoryRamp(exporterIFC, ramp, numFlights,
                            ownerHistory, localPlacement, containedRampLocalPlacement, representation,
                            rampName, rampObjectType, rampDescription, elementTag, rampType,
                            ecData, placementSetter, productWrapper);
                    }
                    PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, ramp, productWrapper);
                    tr.Commit();
                }
            }
        }
Beispiel #12
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 IFCProductWrapper.
        /// </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,
                                       IFCProductWrapper productWrapper, bool exportParts)
        {
            if (geometryElement == null)
            {
                return;
            }

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

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

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

                        IList <IFCAnyHandle>             reps            = new List <IFCAnyHandle>();
                        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.GetSolidMeshGeometry(geometryElement, Transform.Identity);
                                IList <Solid>         solids        = solidMeshInfo.GetSolids();
                                IList <Mesh>          meshes        = solidMeshInfo.GetMeshes();

                                if (solids.Count == 1 && meshes.Count == 0)
                                {
                                    IList <Solid> splitVolumes = SolidUtils.SplitVolumes(solids[0]);
                                    if (splitVolumes.Count == 1)
                                    {
                                        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);
                                                reps.Add(prodRep);

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


                            // Use internal routine as backup that handles openings.
                            if (reps.Count == 0)
                            {
                                exportedAsInternalExtrusion = ExporterIFCUtils.ExportSlabAsExtrusion(exporterIFC, floorElement,
                                                                                                     geometryElement, transformSetter, localPlacement, out localPlacements, out reps,
                                                                                                     out extrusionLoops, out loopExtraParams, floorPlane);
                            }

                            if (reps.Count == 0)
                            {
                                using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                                {
                                    BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                                    bodyExporterOptions.TessellationLevel = BodyExporterOptions.BodyTessellationLevel.Coarse;
                                    IFCAnyHandle prodDefHnd = RepresentationUtil.CreateBRepProductDefinitionShape(floorElement.Document.Application, exporterIFC,
                                                                                                                  floorElement, catId, geometryElement, bodyExporterOptions, null, ecData);
                                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodDefHnd))
                                    {
                                        ecData.ClearOpenings();
                                        return;
                                    }

                                    reps.Add(prodDefHnd);
                                }
                            }
                        }

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

                        int numReps = exportParts ? 1 : reps.Count;
                        for (int ii = 0; ii < numReps; ii++)
                        {
                            string ifcName        = NamingUtil.GetNameOverride(floorElement, NamingUtil.CreateIFCName(exporterIFC, ii == 0 ? -1 : ii + 1));
                            string ifcDescription = NamingUtil.GetDescriptionOverride(floorElement, null);
                            string ifcObjectType  = NamingUtil.GetObjectTypeOverride(floorElement, exporterIFC.GetFamilyName());
                            string ifcElemId      = NamingUtil.CreateIFCElementId(floorElement);

                            string       currentGUID       = (ii == 0) ? ifcGUID : ExporterIFCUtils.CreateGUID();
                            IFCAnyHandle localPlacementHnd = exportedAsInternalExtrusion ? localPlacements[ii] : localPlacement;
                            IFCSlabType  slabType          = GetIFCSlabType(ifcEnumType);

                            IFCAnyHandle slabHnd = IFCInstanceExporter.CreateSlab(file, currentGUID, ownerHistory, ifcName,
                                                                                  ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : reps[ii], ifcElemId, slabType);

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

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

                            slabHnds.Add(slabHnd);
                        }

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

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

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, floorElement, productWrapper);
                    }

                    if (!exportParts)
                    {
                        HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement as HostObject, slabHnds,
                                                                     geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3);
                    }
                }
                tr.Commit();

                return;
            }
        }
Beispiel #13
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 IFCProductWrapper object.</param>
        public static void ExportPart(ExporterIFC exporterIFC, Element partElement, IFCProductWrapper productWrapper,
            IFCPlacementSetter placementSetter, IFCAnyHandle originalPlacement, IFCRange range, IFCExtrusionAxes ifcExtrusionAxes,
            Element hostElement, ElementId overrideLevelId, bool asBuildingElement)
        {
            if (!ElementFilteringUtil.IsElementVisible(ExporterCacheManager.ExportOptionsCache.FilterViewForExport, partElement))
                return;

            Part part = partElement as Part;
            if (part == null)
                return;

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

            ElementId partExportLevel = null;
            if (standaloneExport || asBuildingElement)
            {
                if (partElement.Level != null)
                    partExportLevel = partElement.Level.Id;
            }
            else
            {
                if (part.OriginalCategoryId != hostElement.Category.Id)
                    return;
                partExportLevel = hostElement.Level.Id;
            }
            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 = IFCPlacementSetter.Create(exporterIFC, partElement, null, orientationTrf, partExportLevel);
                        partPlacement = standalonePlacementSetter.GetPlacement();
                    }
                    else
                        partPlacement = ExporterUtil.CopyLocalPlacement(file, originalPlacement);

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

                    SolidMeshGeometryInfo solidMeshInfo;
                    if (validRange)
                    {
                        solidMeshInfo = GeometryUtil.GetClippedSolidMeshGeometry(geometryElement, range);
                        if (solidMeshInfo.GetSolids().Count == 0 && solidMeshInfo.GetMeshes().Count == 0)
                            return;
                    }
                    else
                    {
                        solidMeshInfo = GeometryUtil.GetSolidMeshGeometry(geometryElement, Transform.Identity);
                    }

                    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);

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

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

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

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

                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

                        string partGUID = ExporterIFCUtils.CreateGUID(partElement);
                        string origPartName = NamingUtil.CreateIFCName(exporterIFC, -1);
                        string partName = NamingUtil.GetNameOverride(partElement, origPartName);
                        string partDescription = NamingUtil.GetDescriptionOverride(partElement, null);
                        string partObjectType = NamingUtil.GetObjectTypeOverride(partElement, NamingUtil.CreateIFCObjectName(exporterIFC, partElement));
                        string partElemId = NamingUtil.CreateIFCElementId(partElement);

                        IFCAnyHandle ifcPart = null;
                        if (!asBuildingElement)
                        {
                            ifcPart = IFCInstanceExporter.CreateBuildingElementPart(file, partGUID, ownerHistory, partName, partDescription, 
                                partObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, partElemId);
                        }
                        else
                        {
                            string ifcEnumType;
                            IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType);
                            switch (exportType)
                            {
                                case IFCExportType.ExportColumnType:
                                    ifcPart = IFCInstanceExporter.CreateColumn(file, partGUID, ownerHistory, partName, partDescription, partObjectType, 
                                        extrusionCreationData.GetLocalPlacement(), prodRep, partElemId);
                                    break;
                                case IFCExportType.ExportCovering:
                                    IFCCoveringType coveringType = CeilingExporter.GetIFCCoveringType(hostElement, ifcEnumType);
                                    ifcPart = IFCInstanceExporter.CreateCovering(file, partGUID, ownerHistory, partName, partDescription, partObjectType, 
                                        extrusionCreationData.GetLocalPlacement(), prodRep, partElemId, coveringType);
                                    break;
                                case IFCExportType.ExportFooting:
                                    IFCFootingType footingType = FootingExporter.GetIFCFootingType(hostElement, ifcEnumType);
                                    ifcPart = IFCInstanceExporter.CreateFooting(file, partGUID, ownerHistory, partName, partDescription, partObjectType, 
                                        extrusionCreationData.GetLocalPlacement(), prodRep, partElemId, footingType);
                                    break;
                                case IFCExportType.ExportRoof:
                                    IFCRoofType roofType = RoofExporter.GetIFCRoofType(ifcEnumType);
                                    ifcPart = IFCInstanceExporter.CreateRoof(file, partGUID, ownerHistory, partName, partDescription, partObjectType, 
                                        extrusionCreationData.GetLocalPlacement(), prodRep, partElemId, roofType);
                                    break;
                                case IFCExportType.ExportSlab:
                                    IFCSlabType slabType = FloorExporter.GetIFCSlabType(ifcEnumType);
                                    ifcPart = IFCInstanceExporter.CreateSlab(file, partGUID, ownerHistory, partName, partDescription, partObjectType, 
                                        extrusionCreationData.GetLocalPlacement(), prodRep, partElemId, slabType);
                                    break;
                                case IFCExportType.ExportWall:
                                    ifcPart = IFCInstanceExporter.CreateWallStandardCase(file, partGUID, ownerHistory, partName, partDescription, 
                                        partObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, partElemId);
                                    break;
                                default:
                                    ifcPart = IFCInstanceExporter.CreateBuildingElementProxy(file, partGUID, ownerHistory, partName, partDescription, 
                                        partObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, partElemId, IFCElementComposition.Element);
                                    break;
                            }
                        }

                        productWrapper.AddElement(ifcPart, standaloneExport || asBuildingElement ? standalonePlacementSetter : placementSetter, extrusionCreationData, standaloneExport || asBuildingElement);

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

                        CategoryUtil.CreateMaterialAssociations(partElement.Document, exporterIFC, ifcPart, bodyData.MaterialIds);

                        transaction.Commit();
                    }
                }
            }
            finally
            {
                if (standalonePlacementSetter != null)
                    standalonePlacementSetter.Dispose();
            }
        }
Beispiel #14
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 IFCProductWrapper.
        /// </param>
        public static void ExportRailing(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, string ifcEnumType, IFCProductWrapper productWrapper)
        {
            ElementType elemType = element.Document.GetElement(element.GetTypeId()) as ElementType;
            IFCFile file = exporterIFC.GetFile();
            Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(setter.GetPlacement());

                        SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSolidMeshGeometry(geomElem, Transform.Identity);
                        IList<Solid> solids = solidMeshInfo.GetSolids();
                        IList<Mesh> meshes = solidMeshInfo.GetMeshes();

                        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));

                                SolidMeshGeometryInfo subElementSolidMeshInfo = GeometryUtil.GetSolidMeshGeometry(subElementGeom, Transform.Identity);
                                IList<Solid> subElementSolids = subElementSolidMeshInfo.GetSolids();
                                IList<Mesh> subElementMeshes = subElementSolidMeshInfo.GetMeshes();
                                foreach (Solid subElementSolid in subElementSolids)
                                    solids.Add(subElementSolid);
                                foreach (Mesh subElementMesh in subElementMeshes)
                                    meshes.Add(subElementMesh);
                            }
                        }

                        ElementId catId = CategoryUtil.GetSafeCategoryId(element);
                        BodyData bodyData = null;
                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                        //bodyExporterOptions.UseGroupsIfPossible = true;
                        //bodyExporterOptions.UseMappedGeometriesIfPossible = true;
                        bodyExporterOptions.TessellationLevel = BodyExporterOptions.BodyTessellationLevel.Coarse;

                        if (solids.Count > 0 || meshes.Count > 0)
                        {
                            bodyData = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, catId, solids, meshes, bodyExporterOptions, ecData);
                        }
                        else
                        {
                            IList<GeometryObject> geomlist = new List<GeometryObject>();
                            geomlist.Add(geomElem);
                            bodyData = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, catId, 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);

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

                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

                        string instanceGUID = ExporterIFCUtils.CreateGUID(element);
                        string origInstanceName = exporterIFC.GetName();
                        string instanceName = NamingUtil.GetNameOverride(element, origInstanceName);
                        string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceObjectType = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                        string instanceElemId = NamingUtil.CreateIFCElementId(element);
                        Toolkit.IFCRailingType railingType = GetIFCRailingType(element, ifcEnumType);

                        IFCAnyHandle railing = IFCInstanceExporter.CreateRailing(file, instanceGUID, ownerHistory,
                            instanceName, instanceDescription, instanceObjectType, ecData.GetLocalPlacement(),
                            prodRep, instanceElemId, railingType);

                        ElementId hostId = GetStairOrRampHostId(exporterIFC, element as Railing);
                        bool associateToLevel = (hostId == ElementId.InvalidElementId) && LevelUtil.AssociateElementToLevel(element);

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

                        CategoryUtil.CreateMaterialAssociations(element.Document, exporterIFC, railing, bodyData.MaterialIds);

                        // Create multi-story duplicates of this railing.
                        if (hostId != ElementId.InvalidElementId)
                        {
                            StairRampContainerInfo stairRampInfo = ExporterCacheManager.StairRampContainerInfoCache.GetStairRampContainerInfo(hostId);
                            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(railingHndCopy, (IFCLevelInfo)null, ecData, false);
                                    CategoryUtil.CreateMaterialAssociations(element.Document, exporterIFC, railingHndCopy, bodyData.MaterialIds);
                                }
                            }

                            ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(hostId, stairRampInfo);
                        }

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);
                    }
                    transaction.Commit();
                }
            }
        }
Beispiel #15
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 IFCProductWrapper.
        /// </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, 
            IFCProductWrapper productWrapper, bool exportParts)
        {
            if (geometryElement == null)
                return;

            IFCFile file = exporterIFC.GetFile();
            IList<IFCAnyHandle> slabHnds = new List<IFCAnyHandle>();
                        
            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCTransformSetter transformSetter = IFCTransformSetter.Create())
                {
                    using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, floorElement))
                    {
                        IFCAnyHandle localPlacement = placementSetter.GetPlacement();
                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                        bool exportedAsInternalExtrusion = false;

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

                        IList<IFCAnyHandle> reps = new List<IFCAnyHandle>();
                        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.GetSolidMeshGeometry(geometryElement, Transform.Identity);
                                IList<Solid> solids = solidMeshInfo.GetSolids();
                                IList<Mesh> meshes = solidMeshInfo.GetMeshes();

                                if (solids.Count == 1 && meshes.Count == 0)
                                {
                                    IList<Solid> splitVolumes = SolidUtils.SplitVolumes(solids[0]);
                                    if (splitVolumes.Count == 1)
                                    {
                                        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);
                                                reps.Add(prodRep);

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

                            // Use internal routine as backup that handles openings.
                            if (reps.Count == 0)
                            {
                                exportedAsInternalExtrusion = ExporterIFCUtils.ExportSlabAsExtrusion(exporterIFC, floorElement, 
                                    geometryElement, transformSetter, localPlacement, out localPlacements, out reps, 
                                    out extrusionLoops, out loopExtraParams, floorPlane);
                            }

                            if (reps.Count == 0)
                            {
                                using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                                {
                                    BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                                    bodyExporterOptions.TessellationLevel = BodyExporterOptions.BodyTessellationLevel.Coarse;
                                    IFCAnyHandle prodDefHnd = RepresentationUtil.CreateBRepProductDefinitionShape(floorElement.Document.Application, exporterIFC,
                                        floorElement, catId, geometryElement, bodyExporterOptions, null, ecData);
                                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodDefHnd))
                                    {
                                        ecData.ClearOpenings();
                                        return;
                                    }

                                    reps.Add(prodDefHnd);
                                }
                            }
                        }

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

                        int numReps = exportParts ? 1 : reps.Count;
                        for (int ii = 0; ii < numReps; ii++)
                        {
                            string ifcName = NamingUtil.GetNameOverride(floorElement, NamingUtil.CreateIFCName(exporterIFC, ii == 0 ? -1 : ii + 1));
                            string ifcDescription = NamingUtil.GetDescriptionOverride(floorElement, null);
                            string ifcObjectType = NamingUtil.GetObjectTypeOverride(floorElement, exporterIFC.GetFamilyName());
                            string ifcElemId = NamingUtil.CreateIFCElementId(floorElement);

                            string currentGUID = (ii == 0) ? ifcGUID : ExporterIFCUtils.CreateGUID();
                            IFCAnyHandle localPlacementHnd = exportedAsInternalExtrusion ? localPlacements[ii] : localPlacement;
                            IFCSlabType slabType = GetIFCSlabType(ifcEnumType);

                            IFCAnyHandle slabHnd = IFCInstanceExporter.CreateSlab(file, currentGUID, ownerHistory, ifcName,
                               ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : reps[ii], ifcElemId, slabType);

                            if (IFCAnyHandleUtil.IsNullOrHasNoValue(slabHnd))
                                return;

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

                            slabHnds.Add(slabHnd);
                        }

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

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

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, floorElement, productWrapper);
                    }

                    if (!exportParts)
                    {
                        HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement as HostObject, slabHnds, 
                            geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3);
                    }
                }
                tr.Commit();

                return;
            }
        }
        /// <summary>
        /// Export Curtain Walls and Roofs.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="hostElement">
        /// The host element to be exported.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportBase(ExporterIFC exporterIFC, ElementSet allSubElements,
           HostObject hostElement, IFCProductWrapper wrapper)
        {
            IFCFile file = exporterIFC.GetFile();
            IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

            IFCPlacementSetter setter = null;
            IFCProductWrapper curtainWallSubWrapper = null;
            try
            {
                IFCAnyHandle localPlacement = IFCAnyHandle.Create();
                bool canExportCurtainWallAsContainer = CanExportCurtainWallAsContainer(allSubElements);
                IFCAnyHandle rep = IFCAnyHandle.Create();
                if (canExportCurtainWallAsContainer)
                {
                    curtainWallSubWrapper = IFCProductWrapper.Create(exporterIFC, true);
                    setter = IFCPlacementSetter.Create(exporterIFC, hostElement);
                    localPlacement = setter.GetPlacement();
                    rep = ExportCurtainObjectCommonAsOneBRep(allSubElements, hostElement, exporterIFC, setter, localPlacement);
                }
                else
                {
                    ExportCurtainObjectCommonAsContainer(allSubElements, hostElement, exporterIFC, out curtainWallSubWrapper);
                    // This has to go LAST.  Why?  Because otherwise we apply the level transform twice -- once in the familyTrf, once here.
                    // This will be used just to put the CurtainWall on the right level.
                    setter = IFCPlacementSetter.Create(exporterIFC, hostElement);
                    localPlacement = setter.GetPlacement();
                }

                if (!rep.HasValue)
                    return;

                IFCLabel objectType = NamingUtil.CreateIFCObjectName(exporterIFC, hostElement);

                IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData();
                extraParams.SetLocalPlacement(localPlacement);

                IFCAnyHandle prodRepHnd = IFCAnyHandle.Create();
                IFCAnyHandle elemHnd = IFCAnyHandle.Create();
                IFCLabel elemGUID = IFCLabel.CreateGUID(hostElement);
                IFCLabel elemName = NamingUtil.GetNameOverride(hostElement, exporterIFC.GetNameFromExportState());
                IFCLabel elemDesc = NamingUtil.GetDescriptionOverride(hostElement, IFCLabel.Create());
                IFCLabel elemType = NamingUtil.GetObjectTypeOverride(hostElement, objectType);
                IFCLabel elemId = NamingUtil.CreateIFCElementId(hostElement);
                if (hostElement is Wall || hostElement is CurtainSystem)
                {
                    elemHnd = file.CreateCurtainWall(elemGUID, ownerHistory, elemName, elemDesc, elemType, localPlacement, elemId, prodRepHnd);
                }
                else if (hostElement is RoofBase)
                {
                    string ifcEnumType = CategoryUtil.GetIFCEnumTypeName(exporterIFC, hostElement);
                    elemHnd = file.CreateRoof(elemGUID, ownerHistory, elemName, elemDesc, elemType, localPlacement, elemId, ifcEnumType, prodRepHnd);
                }
                else
                {
                    return;
                }

                if (!elemHnd.HasValue)
                    return;

                wrapper.AddElement(elemHnd, setter, extraParams, true);
                OpeningUtil.CreateOpeningsIfNecessary(elemHnd, hostElement, extraParams, exporterIFC, localPlacement, setter, wrapper);

                ExporterIFCUtils.CreateCurtainWallPropertySet(exporterIFC, hostElement, wrapper);
                ICollection<IFCAnyHandle> relatedElementIds = curtainWallSubWrapper.GetAllObjects();
                if (relatedElementIds.Count > 0)
                {
                    IFCLabel guid = IFCLabel.CreateGUID();
                    IFCLabel nameOpt = IFCLabel.Create();
                    IFCLabel descOpt = IFCLabel.Create();
                    file.CreateRelAggregates(guid, ownerHistory, nameOpt, descOpt, elemHnd, relatedElementIds);
                }
                exporterIFC.RegisterSpaceBoundingElementHandle(elemHnd, hostElement.Id, ElementId.InvalidElementId);
            }
            finally
            {
                if (setter != null)
                    setter.Dispose();
                if (curtainWallSubWrapper != null)
                    curtainWallSubWrapper.Dispose();
            }
        }
Beispiel #17
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 IFCProductWrapper.</param>
        /// <param name="setter">The IFCPlacementSetter.</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="instanceElemId">The element id label.</param>
        /// <returns>The handle.</returns>
        public static IFCAnyHandle ExportGenericInstance(IFCExportType type,
           ExporterIFC exporterIFC, Element familyInstance,
           IFCProductWrapper wrapper, IFCPlacementSetter setter, IFCExtrusionCreationData extraParams,
           string instanceGUID, IFCAnyHandle ownerHistory,
           string instanceName, string instanceDescription, string instanceObjectType,
           IFCAnyHandle productRepresentation,
           string instanceElemId)
        {
            IFCFile file = exporterIFC.GetFile();
            Document doc = familyInstance.Document;

            bool isRoomRelated = IsRoomRelated(type);

            IFCAnyHandle localPlacementToUse = setter.GetPlacement();
            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.ExportColumnType:
                    {
                        instanceHandle = IFCInstanceExporter.CreateColumn(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        break;
                    }
                case IFCExportType.ExportMemberType:
                    {
                        instanceHandle = IFCInstanceExporter.CreateMember(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        break;
                    }
                case IFCExportType.ExportPlateType:
                    {
                        instanceHandle = IFCInstanceExporter.CreatePlate(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        break;
                    }
                case IFCExportType.ExportDistributionControlElement:
                    {
                        instanceHandle = IFCInstanceExporter.CreateDistributionControlElement(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId,
                           null);
                        break;
                    }
                case IFCExportType.ExportDistributionElement:
                    {
                        instanceHandle = IFCInstanceExporter.CreateDistributionElement(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        break;
                    }
                default:
                    {
                        if ((type == IFCExportType.ExportFurnishingElement) || IsFurnishingElementSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFurnishingElement(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if ((type == IFCExportType.ExportEnergyConversionDevice) || IsEnergyConversionDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateEnergyConversionDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if ((type == IFCExportType.ExportFlowFitting) || IsFlowFittingSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowFitting(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if ((type == IFCExportType.ExportFlowMovingDevice) || IsFlowMovingDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowMovingDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if ((type == IFCExportType.ExportFlowSegment) || IsFlowSegmentSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowSegment(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if ((type == IFCExportType.ExportFlowStorageDevice) || IsFlowStorageDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowStorageDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if ((type == IFCExportType.ExportFlowTerminal) || IsFlowTerminalSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowTerminal(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if ((type == IFCExportType.ExportFlowTreatmentDevice) || IsFlowTreatmentDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowTreatmentDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if ((type == IFCExportType.ExportFlowController) || IsFlowControllerSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowController(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if ((type == IFCExportType.ExportDistributionFlowElement) || IsDistributionFlowElementSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateDistributionFlowElement(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        break;
                    }
            }

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle))
            {
                if (roomId == ElementId.InvalidElementId)
                {
                    wrapper.AddElement(instanceHandle, setter, extraParams, true);
                }
                else
                {
                    exporterIFC.RelateSpatialElement(roomId, instanceHandle);
                    wrapper.AddElement(instanceHandle, setter, extraParams, false);
                }
            }
            return instanceHandle;
        }
Beispiel #18
0
        /// <summary>
        /// Exports a gutter element.
        /// </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 ExportGutter(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(setter.GetPlacement());

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions();
                        IFCAnyHandle        bodyRep             = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, categoryId,
                                                                                          geometryElement, bodyExporterOptions, ecData).RepresentationHnd;
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep))
                        {
                            if (ecData != null)
                            {
                                ecData.ClearOpenings();
                            }
                            return;
                        }

                        IFCAnyHandle        origin      = ExporterUtil.CreateAxis2Placement3D(file);
                        IFCAnyHandle        repMap3dHnd = IFCInstanceExporter.CreateRepresentationMap(file, origin, bodyRep);
                        List <IFCAnyHandle> repMapList  = new List <IFCAnyHandle>();
                        repMapList.Add(repMap3dHnd);
                        string       elementTypeName = NamingUtil.CreateIFCObjectName(exporterIFC, element);
                        IFCAnyHandle style           = IFCInstanceExporter.CreatePipeSegmentType(file, ExporterIFCUtils.CreateGUID(element), exporterIFC.GetOwnerHistoryHandle(),
                                                                                                 elementTypeName, null, null, null, repMapList, NamingUtil.CreateIFCElementId(element), elementTypeName, IFCPipeSegmentType.Gutter);


                        List <IFCAnyHandle> representationMaps = GeometryUtil.GetRepresentationMaps(style);
                        IFCAnyHandle        mappedItem         = ExporterUtil.CreateDefaultMappedItem(file, representationMaps[0]);

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

                        IFCAnyHandle bodyMappedItemRep = RepresentationUtil.CreateBodyMappedItemRep(exporterIFC,
                                                                                                    element, categoryId, exporterIFC.Get3DContextHandle("Body"), representations);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyMappedItemRep))
                        {
                            return;
                        }

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

                        IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                        IFCAnyHandle localPlacementToUse;
                        ElementId    roomId = setter.UpdateRoomRelativeCoordinates(element, out localPlacementToUse);
                        if (roomId == ElementId.InvalidElementId)
                        {
                            localPlacementToUse = ecData.GetLocalPlacement();
                        }
                        string       name        = NamingUtil.GetNameOverride(element, NamingUtil.CreateIFCName(exporterIFC, -1));
                        string       description = NamingUtil.GetDescriptionOverride(element, null);
                        string       objectType  = NamingUtil.GetObjectTypeOverride(element, elementTypeName);
                        IFCAnyHandle elemHnd     = IFCInstanceExporter.CreateFlowSegment(file, ExporterIFCUtils.CreateGUID(element),
                                                                                         exporterIFC.GetOwnerHistoryHandle(), name, description, objectType, localPlacementToUse, prodRep,
                                                                                         NamingUtil.CreateIFCElementId(element));

                        if (roomId == ElementId.InvalidElementId)
                        {
                            productWrapper.AddElement(elemHnd, setter.GetLevelInfo(), ecData, true);
                        }
                        else
                        {
                            exporterIFC.RelateSpatialElement(roomId, elemHnd);
                            productWrapper.AddElement(elemHnd, setter.GetLevelInfo(), ecData, false);
                        }

                        OpeningUtil.CreateOpeningsIfNecessary(elemHnd, element, ecData, exporterIFC,
                                                              localPlacementToUse, setter, productWrapper);
                    }

                    tr.Commit();
                }
            }
        }
Beispiel #19
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 IFCProductWrapper.
        /// </param>
        public static void ExportRailing(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, string ifcEnumType, IFCProductWrapper productWrapper)
        {
            ElementType elemType    = element.Document.GetElement(element.GetTypeId()) as ElementType;
            IFCFile     file        = exporterIFC.GetFile();
            Options     geomOptions = GeometryUtil.GetIFCExportGeometryOptions();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(setter.GetPlacement());

                        SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSolidMeshGeometry(geomElem, Transform.Identity);
                        IList <Solid>         solids        = solidMeshInfo.GetSolids();
                        IList <Mesh>          meshes        = solidMeshInfo.GetMeshes();

                        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));

                                SolidMeshGeometryInfo subElementSolidMeshInfo = GeometryUtil.GetSolidMeshGeometry(subElementGeom, Transform.Identity);
                                IList <Solid>         subElementSolids        = subElementSolidMeshInfo.GetSolids();
                                IList <Mesh>          subElementMeshes        = subElementSolidMeshInfo.GetMeshes();
                                foreach (Solid subElementSolid in subElementSolids)
                                {
                                    solids.Add(subElementSolid);
                                }
                                foreach (Mesh subElementMesh in subElementMeshes)
                                {
                                    meshes.Add(subElementMesh);
                                }
                            }
                        }

                        ElementId           catId               = CategoryUtil.GetSafeCategoryId(element);
                        BodyData            bodyData            = null;
                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                        //bodyExporterOptions.UseGroupsIfPossible = true;
                        //bodyExporterOptions.UseMappedGeometriesIfPossible = true;
                        bodyExporterOptions.TessellationLevel = BodyExporterOptions.BodyTessellationLevel.Coarse;

                        if (solids.Count > 0 || meshes.Count > 0)
                        {
                            bodyData = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, catId, solids, meshes, bodyExporterOptions, ecData);
                        }
                        else
                        {
                            IList <GeometryObject> geomlist = new List <GeometryObject>();
                            geomlist.Add(geomElem);
                            bodyData = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, catId, 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);

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

                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

                        string instanceGUID                = ExporterIFCUtils.CreateGUID(element);
                        string origInstanceName            = exporterIFC.GetName();
                        string instanceName                = NamingUtil.GetNameOverride(element, origInstanceName);
                        string instanceDescription         = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceObjectType          = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                        string instanceElemId              = NamingUtil.CreateIFCElementId(element);
                        Toolkit.IFCRailingType railingType = GetIFCRailingType(element, ifcEnumType);

                        IFCAnyHandle railing = IFCInstanceExporter.CreateRailing(file, instanceGUID, ownerHistory,
                                                                                 instanceName, instanceDescription, instanceObjectType, ecData.GetLocalPlacement(),
                                                                                 prodRep, instanceElemId, railingType);

                        ElementId hostId           = GetStairOrRampHostId(exporterIFC, element as Railing);
                        bool      associateToLevel = (hostId == ElementId.InvalidElementId) && LevelUtil.AssociateElementToLevel(element);

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

                        CategoryUtil.CreateMaterialAssociations(element.Document, exporterIFC, railing, bodyData.MaterialIds);

                        // Create multi-story duplicates of this railing.
                        if (hostId != ElementId.InvalidElementId)
                        {
                            StairRampContainerInfo stairRampInfo = ExporterCacheManager.StairRampContainerInfoCache.GetStairRampContainerInfo(hostId);
                            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(railingHndCopy, (IFCLevelInfo)null, ecData, false);
                                    CategoryUtil.CreateMaterialAssociations(element.Document, exporterIFC, railingHndCopy, bodyData.MaterialIds);
                                }
                            }

                            ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(hostId, stairRampInfo);
                        }

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);
                    }
                    transaction.Commit();
                }
            }
        }
Beispiel #20
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();
            }
        }
Beispiel #21
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();
            }
        }
Beispiel #22
0
        /// <summary>
        /// Exports a gutter element.
        /// </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 ExportGutter(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(setter.GetPlacement());

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions();
                        IFCAnyHandle bodyRep = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, categoryId,
                            geometryElement, bodyExporterOptions, ecData).RepresentationHnd;
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep))
                        {
                            if (ecData != null)
                                ecData.ClearOpenings();
                            return;
                        }

                        IFCAnyHandle origin = ExporterUtil.CreateAxis2Placement3D(file);
                        IFCAnyHandle repMap3dHnd = IFCInstanceExporter.CreateRepresentationMap(file, origin, bodyRep);
                        List<IFCAnyHandle> repMapList = new List<IFCAnyHandle>();
                        repMapList.Add(repMap3dHnd);
                        string elementTypeName = NamingUtil.CreateIFCObjectName(exporterIFC, element);
                        IFCAnyHandle style = IFCInstanceExporter.CreatePipeSegmentType(file, ExporterIFCUtils.CreateGUID(element), exporterIFC.GetOwnerHistoryHandle(),
                            elementTypeName, null, null, null, repMapList, NamingUtil.CreateIFCElementId(element), elementTypeName, IFCPipeSegmentType.Gutter);


                        List<IFCAnyHandle> representationMaps = GeometryUtil.GetRepresentationMaps(style);
                        IFCAnyHandle mappedItem = ExporterUtil.CreateDefaultMappedItem(file, representationMaps[0]);

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

                        IFCAnyHandle bodyMappedItemRep = RepresentationUtil.CreateBodyMappedItemRep(exporterIFC,
                            element, categoryId, exporterIFC.Get3DContextHandle("Body"), representations);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyMappedItemRep))
                            return;

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

                        IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                        IFCAnyHandle localPlacementToUse;
                        ElementId roomId = setter.UpdateRoomRelativeCoordinates(element, out localPlacementToUse);
                        if (roomId == ElementId.InvalidElementId)
                            localPlacementToUse = ecData.GetLocalPlacement();
                        string name = NamingUtil.GetNameOverride(element, NamingUtil.CreateIFCName(exporterIFC, -1));
                        string description = NamingUtil.GetDescriptionOverride(element, null);
                        string objectType = NamingUtil.GetObjectTypeOverride(element, elementTypeName);
                        IFCAnyHandle elemHnd = IFCInstanceExporter.CreateFlowSegment(file, ExporterIFCUtils.CreateGUID(element),
                            exporterIFC.GetOwnerHistoryHandle(), name, description, objectType, localPlacementToUse, prodRep,
                            NamingUtil.CreateIFCElementId(element));

                        if (roomId == ElementId.InvalidElementId)
                        {
                            productWrapper.AddElement(elemHnd, setter.GetLevelInfo(), ecData, true);
                        }
                        else
                        {
                            exporterIFC.RelateSpatialElement(roomId, elemHnd);
                            productWrapper.AddElement(elemHnd, setter.GetLevelInfo(), ecData, false);
                        }

                        OpeningUtil.CreateOpeningsIfNecessary(elemHnd, element, ecData, exporterIFC,
                           localPlacementToUse, setter, productWrapper);
                    }

                    tr.Commit();
                }
            }
        }
Beispiel #23
0
        /// <summary>
        /// Exports a beam to IFC beam.
        /// </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 IFCProductWrapper.
        /// </param>
        public static void ExportBeam(ExporterIFC exporterIFC,
           Element element, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            if (geometryElement == null)
                return;

            IFCFile file = exporterIFC.GetFile();
            double scale = exporterIFC.LinearScale;

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                LocationCurve locCurve = element.Location as LocationCurve;
                Transform orientTrf = Transform.Identity;

                bool canExportAxis = (locCurve != null);
                IFCAnyHandle axisRep = null;

                XYZ beamDirection = null;
                XYZ projDir = null;
                Curve curve = null;

                Plane plane = null;
                if (canExportAxis)
                {
                    curve = locCurve.Curve;
                    if (curve is Line)
                    {
                        Line line = curve as Line;
                        XYZ planeY, planeOrig;
                        planeOrig = line.get_EndPoint(0);
                        beamDirection = line.Direction;
                        if (Math.Abs(beamDirection.Z) < 0.707)  // approx 1.0/sqrt(2.0)
                        {
                            planeY = XYZ.BasisZ.CrossProduct(beamDirection);
                        }
                        else
                        {
                            planeY = XYZ.BasisX.CrossProduct(beamDirection);
                        }
                        planeY = planeY.Normalize();
                        projDir = beamDirection.CrossProduct(planeY);
                        plane = new Plane(beamDirection, planeY, planeOrig);
                        orientTrf.BasisX = beamDirection; orientTrf.BasisY = planeY; orientTrf.BasisZ = projDir; orientTrf.Origin = planeOrig;
                    }
                    else if (curve is Arc)
                    {
                        XYZ yDir, center;
                        Arc arc = curve as Arc;
                        beamDirection = arc.XDirection; yDir = arc.YDirection; projDir = arc.Normal; center = arc.Center;
                        plane = new Plane(beamDirection, yDir, center);
                        orientTrf.BasisX = beamDirection; orientTrf.BasisY = yDir; orientTrf.BasisZ = projDir; orientTrf.Origin = center;
                    }
                    else
                        canExportAxis = false;
                }

                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element, null, canExportAxis ? orientTrf : null, ElementId.InvalidElementId))
                {
                    IFCAnyHandle localPlacement = setter.GetPlacement();
                    SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSolidMeshGeometry(geometryElement, Transform.Identity);

                    using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData())
                    {
                        extrusionCreationData.SetLocalPlacement(localPlacement);
                        if (canExportAxis && (orientTrf.BasisX != null))
                        {
                            extrusionCreationData.CustomAxis = beamDirection;
                            extrusionCreationData.PossibleExtrusionAxes = IFCExtrusionAxes.TryCustom;
                        }
                        else
                            extrusionCreationData.PossibleExtrusionAxes = IFCExtrusionAxes.TryXY;

                        IList<Solid> solids = solidMeshInfo.GetSolids();
                        IList<Mesh> meshes = solidMeshInfo.GetMeshes();
                        
                        ElementId catId = CategoryUtil.GetSafeCategoryId(element);

                        // The representation handle generated from one of the methods below.
                        IFCAnyHandle repHnd = null;

                        // The list of materials in the solids or meshes.
                        ICollection<ElementId> materialIds = new HashSet<ElementId>();

                        // If we can only export as a BRep, there may be an offset to make the BRep local coordinate system
                        // be near the origin.  This offset will be used to move the axis to the new LCS.
                        Transform brepOffsetTransform = null;
                        
                        // If we have a beam with a Linear location line that only has one solid geometry,
                        // we will try to use the ExtrusionAnalyzer to generate an extrusion with 0 or more clippings.
                        // This code is currently limited in that it will not process beams with openings, so we
                        // use other methods below if this one fails.
                        if (solids.Count == 1 && meshes.Count == 0 && (canExportAxis && (curve is Line)))
                        {
                            IList<Solid> splitVolumes = SolidUtils.SplitVolumes(solids[0]);
                            if (splitVolumes.Count == 1)
                            {
                                bool completelyClipped;
                                beamDirection = orientTrf.BasisX;
                                Plane beamExtrusionPlane = new Plane(orientTrf.BasisY, orientTrf.BasisZ, orientTrf.Origin);
                                repHnd = ExtrusionExporter.CreateExtrusionWithClipping(exporterIFC, element,
                                    catId, solids[0], beamExtrusionPlane, beamDirection, null, out completelyClipped);
                                if (completelyClipped)
                                    return;

                                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd))
                                {
                                    ElementId materialId = BodyExporter.GetBestMaterialIdForGeometry(solids[0], exporterIFC);
                                    if (materialId != ElementId.InvalidElementId)
                                        materialIds.Add(materialId);
                                }
                            }
                        }

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd))
                        {
                            BodyData bodyData = null;

                            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                            if (solids.Count > 0 || meshes.Count > 0)
                            {
                                bodyData = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, catId,
                                    solids, meshes, bodyExporterOptions, extrusionCreationData);
                            }
                            else
                            {
                                IList<GeometryObject> geomlist = new List<GeometryObject>();
                                geomlist.Add(geometryElement);
                                bodyData = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, catId, geomlist,
                                    bodyExporterOptions, extrusionCreationData);
                            }
                            repHnd = bodyData.RepresentationHnd;
                            materialIds = bodyData.MaterialIds;
                            brepOffsetTransform = bodyData.BrepOffsetTransform;
                        }

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd))
                        {
                            extrusionCreationData.ClearOpenings();
                            return;
                        }

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

                        if (canExportAxis)
                        {
                            XYZ curveOffset = new XYZ(0, 0, 0);
                            if (brepOffsetTransform != null)
                            {
                                curveOffset = -brepOffsetTransform.Origin / scale;
                            }
                            else
                            {
                                // Note that we do not have to have any scaling adjustment here, since the curve origin is in the 
                                // same internal coordinate system as the curve.
                                curveOffset = -plane.Origin;
                            }

                            Plane offsetPlane = new Plane(plane.XVec, plane.YVec, XYZ.Zero);
                            IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, offsetPlane, projDir, false);
                            ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, curve, curveOffset, true);
                            
                            IList<IFCAnyHandle> axis_items = info.GetCurves();

                            if (axis_items.Count > 0)
                            {
                                string identifierOpt = "Axis";	// this is by IFC2x2 convention, not temporary
                                string representationTypeOpt = "Curve2D";  // this is by IFC2x2 convention, not temporary
                                axisRep = RepresentationUtil.CreateShapeRepresentation(exporterIFC, element, catId, exporterIFC.Get3DContextHandle(identifierOpt),
                                   identifierOpt, representationTypeOpt, axis_items);
                                representations.Add(axisRep);
                            }
                        }
                        representations.Add(repHnd);

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

                        string instanceGUID = ExporterIFCUtils.CreateGUID(element);
                        string origInstanceName = exporterIFC.GetName();
                        string instanceName = NamingUtil.GetNameOverride(element, origInstanceName);
                        string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceObjectType = NamingUtil.GetObjectTypeOverride(element, NamingUtil.CreateIFCObjectName(exporterIFC, element));
                        string instanceElemId = NamingUtil.CreateIFCElementId(element);

                        IFCAnyHandle beam = IFCInstanceExporter.CreateBeam(file, instanceGUID, exporterIFC.GetOwnerHistoryHandle(),
                            instanceName, instanceDescription, instanceObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, instanceElemId);

                        productWrapper.AddElement(beam, setter, extrusionCreationData, LevelUtil.AssociateElementToLevel(element));

                        OpeningUtil.CreateOpeningsIfNecessary(beam, element, extrusionCreationData, exporterIFC, extrusionCreationData.GetLocalPlacement(), setter, productWrapper);

                        FamilyTypeInfo typeInfo = new FamilyTypeInfo();
                        typeInfo.ScaledDepth = extrusionCreationData.ScaledLength;
                        typeInfo.ScaledArea = extrusionCreationData.ScaledArea;
                        typeInfo.ScaledInnerPerimeter = extrusionCreationData.ScaledInnerPerimeter;
                        typeInfo.ScaledOuterPerimeter = extrusionCreationData.ScaledOuterPerimeter;
                        PropertyUtil.CreateBeamColumnBaseQuantities(exporterIFC, beam, element, typeInfo);

                        if (materialIds.Count != 0)
                        {
                            CategoryUtil.CreateMaterialAssociations(element.Document, exporterIFC, beam, materialIds);
                        }

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

                transaction.Commit();
            }
        }
Beispiel #24
0
        /// <summary>
        /// Exports a beam to IFC beam.
        /// </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 IFCProductWrapper.
        /// </param>
        public static void ExportBeam(ExporterIFC exporterIFC,
                                      Element element, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            if (geometryElement == null)
            {
                return;
            }

            IFCFile file  = exporterIFC.GetFile();
            double  scale = exporterIFC.LinearScale;

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                LocationCurve locCurve  = element.Location as LocationCurve;
                Transform     orientTrf = Transform.Identity;

                bool         canExportAxis = (locCurve != null);
                IFCAnyHandle axisRep       = null;

                XYZ   beamDirection = null;
                XYZ   projDir       = null;
                Curve curve         = null;

                Plane plane = null;
                if (canExportAxis)
                {
                    curve = locCurve.Curve;
                    if (curve is Line)
                    {
                        Line line = curve as Line;
                        XYZ  planeY, planeOrig;
                        planeOrig     = line.get_EndPoint(0);
                        beamDirection = line.Direction;
                        if (Math.Abs(beamDirection.Z) < 0.707)  // approx 1.0/sqrt(2.0)
                        {
                            planeY = XYZ.BasisZ.CrossProduct(beamDirection);
                        }
                        else
                        {
                            planeY = XYZ.BasisX.CrossProduct(beamDirection);
                        }
                        planeY           = planeY.Normalize();
                        projDir          = beamDirection.CrossProduct(planeY);
                        plane            = new Plane(beamDirection, planeY, planeOrig);
                        orientTrf.BasisX = beamDirection; orientTrf.BasisY = planeY; orientTrf.BasisZ = projDir; orientTrf.Origin = planeOrig;
                    }
                    else if (curve is Arc)
                    {
                        XYZ yDir, center;
                        Arc arc = curve as Arc;
                        beamDirection    = arc.XDirection; yDir = arc.YDirection; projDir = arc.Normal; center = arc.Center;
                        plane            = new Plane(beamDirection, yDir, center);
                        orientTrf.BasisX = beamDirection; orientTrf.BasisY = yDir; orientTrf.BasisZ = projDir; orientTrf.Origin = center;
                    }
                    else
                    {
                        canExportAxis = false;
                    }
                }

                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element, null, canExportAxis ? orientTrf : null, ElementId.InvalidElementId))
                {
                    IFCAnyHandle          localPlacement = setter.GetPlacement();
                    SolidMeshGeometryInfo solidMeshInfo  = GeometryUtil.GetSolidMeshGeometry(geometryElement, Transform.Identity);

                    using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData())
                    {
                        extrusionCreationData.SetLocalPlacement(localPlacement);
                        if (canExportAxis && (orientTrf.BasisX != null))
                        {
                            extrusionCreationData.CustomAxis            = beamDirection;
                            extrusionCreationData.PossibleExtrusionAxes = IFCExtrusionAxes.TryCustom;
                        }
                        else
                        {
                            extrusionCreationData.PossibleExtrusionAxes = IFCExtrusionAxes.TryXY;
                        }

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

                        ElementId catId = CategoryUtil.GetSafeCategoryId(element);

                        // The representation handle generated from one of the methods below.
                        IFCAnyHandle repHnd = null;

                        // The list of materials in the solids or meshes.
                        ICollection <ElementId> materialIds = new HashSet <ElementId>();

                        // If we can only export as a BRep, there may be an offset to make the BRep local coordinate system
                        // be near the origin.  This offset will be used to move the axis to the new LCS.
                        Transform brepOffsetTransform = null;

                        // If we have a beam with a Linear location line that only has one solid geometry,
                        // we will try to use the ExtrusionAnalyzer to generate an extrusion with 0 or more clippings.
                        // This code is currently limited in that it will not process beams with openings, so we
                        // use other methods below if this one fails.
                        if (solids.Count == 1 && meshes.Count == 0 && (canExportAxis && (curve is Line)))
                        {
                            IList <Solid> splitVolumes = SolidUtils.SplitVolumes(solids[0]);
                            if (splitVolumes.Count == 1)
                            {
                                bool completelyClipped;
                                beamDirection = orientTrf.BasisX;
                                Plane beamExtrusionPlane = new Plane(orientTrf.BasisY, orientTrf.BasisZ, orientTrf.Origin);
                                repHnd = ExtrusionExporter.CreateExtrusionWithClipping(exporterIFC, element,
                                                                                       catId, solids[0], beamExtrusionPlane, beamDirection, null, out completelyClipped);
                                if (completelyClipped)
                                {
                                    return;
                                }

                                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd))
                                {
                                    ElementId materialId = BodyExporter.GetBestMaterialIdForGeometry(solids[0], exporterIFC);
                                    if (materialId != ElementId.InvalidElementId)
                                    {
                                        materialIds.Add(materialId);
                                    }
                                }
                            }
                        }

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd))
                        {
                            BodyData bodyData = null;

                            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                            if (solids.Count > 0 || meshes.Count > 0)
                            {
                                bodyData = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, catId,
                                                                   solids, meshes, bodyExporterOptions, extrusionCreationData);
                            }
                            else
                            {
                                IList <GeometryObject> geomlist = new List <GeometryObject>();
                                geomlist.Add(geometryElement);
                                bodyData = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, catId, geomlist,
                                                                   bodyExporterOptions, extrusionCreationData);
                            }
                            repHnd              = bodyData.RepresentationHnd;
                            materialIds         = bodyData.MaterialIds;
                            brepOffsetTransform = bodyData.BrepOffsetTransform;
                        }

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd))
                        {
                            extrusionCreationData.ClearOpenings();
                            return;
                        }

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

                        if (canExportAxis)
                        {
                            XYZ curveOffset = new XYZ(0, 0, 0);
                            if (brepOffsetTransform != null)
                            {
                                curveOffset = -brepOffsetTransform.Origin / scale;
                            }
                            else
                            {
                                // Note that we do not have to have any scaling adjustment here, since the curve origin is in the
                                // same internal coordinate system as the curve.
                                curveOffset = -plane.Origin;
                            }

                            Plane           offsetPlane = new Plane(plane.XVec, plane.YVec, XYZ.Zero);
                            IFCGeometryInfo info        = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, offsetPlane, projDir, false);
                            ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, curve, curveOffset, true);

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

                            if (axis_items.Count > 0)
                            {
                                string identifierOpt         = "Axis";    // this is by IFC2x2 convention, not temporary
                                string representationTypeOpt = "Curve2D"; // this is by IFC2x2 convention, not temporary
                                axisRep = RepresentationUtil.CreateShapeRepresentation(exporterIFC, element, catId, exporterIFC.Get3DContextHandle(identifierOpt),
                                                                                       identifierOpt, representationTypeOpt, axis_items);
                                representations.Add(axisRep);
                            }
                        }
                        representations.Add(repHnd);

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

                        string instanceGUID        = ExporterIFCUtils.CreateGUID(element);
                        string origInstanceName    = exporterIFC.GetName();
                        string instanceName        = NamingUtil.GetNameOverride(element, origInstanceName);
                        string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceObjectType  = NamingUtil.GetObjectTypeOverride(element, NamingUtil.CreateIFCObjectName(exporterIFC, element));
                        string instanceElemId      = NamingUtil.CreateIFCElementId(element);

                        IFCAnyHandle beam = IFCInstanceExporter.CreateBeam(file, instanceGUID, exporterIFC.GetOwnerHistoryHandle(),
                                                                           instanceName, instanceDescription, instanceObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, instanceElemId);

                        productWrapper.AddElement(beam, setter, extrusionCreationData, LevelUtil.AssociateElementToLevel(element));

                        OpeningUtil.CreateOpeningsIfNecessary(beam, element, extrusionCreationData, exporterIFC, extrusionCreationData.GetLocalPlacement(), setter, productWrapper);

                        FamilyTypeInfo typeInfo = new FamilyTypeInfo();
                        typeInfo.ScaledDepth          = extrusionCreationData.ScaledLength;
                        typeInfo.ScaledArea           = extrusionCreationData.ScaledArea;
                        typeInfo.ScaledInnerPerimeter = extrusionCreationData.ScaledInnerPerimeter;
                        typeInfo.ScaledOuterPerimeter = extrusionCreationData.ScaledOuterPerimeter;
                        PropertyUtil.CreateBeamColumnBaseQuantities(exporterIFC, beam, element, typeInfo);

                        if (materialIds.Count != 0)
                        {
                            CategoryUtil.CreateMaterialAssociations(element.Document, exporterIFC, beam, materialIds);
                        }

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

                transaction.Commit();
            }
        }
Beispiel #25
0
        /// <summary>
        /// Creates openings if there is necessary.
        /// </summary>
        /// <param name="elementHandle">
        /// The element handle to create openings.
        /// </param>
        /// <param name="element">
        /// The element to create openings.
        /// </param>
        /// <param name="info">
        /// The extrusion datas.
        /// </param>
        /// <param name="extraParams">
        /// The extrusion creation data.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="originalPlacement">
        /// The original placement handle.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <param name="wrapper">
        /// The IFCProductWrapper.
        /// </param>
        private static void CreateOpeningsIfNecessaryBase(IFCAnyHandle elementHandle, Element element, IList <IFCExtrusionData> info,
                                                          IFCExtrusionCreationData extraParams, ExporterIFC exporterIFC,
                                                          IFCAnyHandle originalPlacement, IFCPlacementSetter setter, IFCProductWrapper wrapper)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(elementHandle))
            {
                return;
            }

            int sz = info.Count;

            if (sz == 0)
            {
                return;
            }

            IFCFile   file       = exporterIFC.GetFile();
            ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);
            Document  document   = element.Document;

            string openingObjectType = "Opening";

            int openingNumber = 1;

            for (int curr = info.Count - 1; curr >= 0; curr--)
            {
                IFCAnyHandle extrusionHandle = ExtrusionExporter.CreateExtrudedSolidFromExtrusionData(exporterIFC, element, info[curr]);
                if (IFCAnyHandleUtil.IsNullOrHasNoValue(extrusionHandle))
                {
                    continue;
                }

                IFCAnyHandle styledItemHnd = BodyExporter.CreateSurfaceStyleForRepItem(exporterIFC, document,
                                                                                       extrusionHandle, ElementId.InvalidElementId);

                HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>();
                bodyItems.Add(extrusionHandle);

                IFCAnyHandle         contextOfItems  = exporterIFC.Get3DContextHandle("Body");
                IFCAnyHandle         bodyRep         = RepresentationUtil.CreateSweptSolidRep(exporterIFC, element, categoryId, contextOfItems, bodyItems, null);
                IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();
                representations.Add(bodyRep);

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

                IFCAnyHandle openingPlacement = ExporterUtil.CopyLocalPlacement(file, originalPlacement);
                string       guid             = ExporterIFCUtils.CreateGUID();
                IFCAnyHandle ownerHistory     = exporterIFC.GetOwnerHistoryHandle();
                string       openingName      = NamingUtil.GetNameOverride(element, NamingUtil.CreateIFCName(exporterIFC, openingNumber++));
                string       elementId        = NamingUtil.CreateIFCElementId(element);
                IFCAnyHandle openingElement   = IFCInstanceExporter.CreateOpeningElement(file, guid, ownerHistory,
                                                                                         openingName, null, openingObjectType, openingPlacement, openingRep, elementId);
                wrapper.AddElement(openingElement, setter, extraParams, true);
                if (ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities && (extraParams != null))
                {
                    ExporterIFCUtils.CreateOpeningQuantities(exporterIFC, openingElement, extraParams);
                }

                string voidGuid = ExporterIFCUtils.CreateGUID();
                IFCInstanceExporter.CreateRelVoidsElement(file, voidGuid, ownerHistory, null, null, elementHandle, openingElement);
            }
        }
        /// <summary>
        /// Export Curtain Walls and Roofs.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="element">
        /// The element to be exported.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportBase(ExporterIFC exporterIFC, ICollection<ElementId> allSubElements,
           Element element, IFCProductWrapper wrapper)
        {
            IFCFile file = exporterIFC.GetFile();
            IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

            IFCPlacementSetter setter = null;

            using (IFCProductWrapper curtainWallSubWrapper = IFCProductWrapper.Create(wrapper, false))
            {
                try
                {
                    IFCAnyHandle localPlacement = null;
                    bool canExportCurtainWallAsContainer = CanExportCurtainWallAsContainer(allSubElements, element.Document);
                    IFCAnyHandle rep = null;
                    if (!canExportCurtainWallAsContainer)
                    {
                        setter = IFCPlacementSetter.Create(exporterIFC, element);
                        localPlacement = setter.GetPlacement();
                        rep = ExportCurtainObjectCommonAsOneBRep(allSubElements, element, exporterIFC, setter, localPlacement);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(rep))
                            return;
                    }
                    else
                    {
                        ExportCurtainObjectCommonAsContainer(allSubElements, element, exporterIFC, curtainWallSubWrapper);
                        // This has to go LAST.  Why?  Because otherwise we apply the level transform twice -- once in the familyTrf, once here.
                        // This will be used just to put the CurtainWall on the right level.
                        setter = IFCPlacementSetter.Create(exporterIFC, element);
                        localPlacement = setter.GetPlacement();
                    }

                    string objectType = NamingUtil.CreateIFCObjectName(exporterIFC, element);

                    {
                        IFCAnyHandle prodRepHnd = null;
                        IFCAnyHandle elemHnd = null;
                        string elemGUID = ExporterIFCUtils.CreateGUID(element);
                        string elemName = NamingUtil.GetNameOverride(element, exporterIFC.GetName());
                        string elemDesc = NamingUtil.GetDescriptionOverride(element, null);
                        string elemType = NamingUtil.GetObjectTypeOverride(element, objectType);
                        string elemId = NamingUtil.CreateIFCElementId(element);
                        if (element is Wall || element is CurtainSystem || IsLegacyCurtainElement(element))
                        {
                            elemHnd = IFCInstanceExporter.CreateCurtainWall(file, elemGUID, ownerHistory, elemName, elemDesc, elemType, localPlacement, prodRepHnd, elemId);
                        }
                        else if (element is RoofBase)
                        {
                            //need to convert the string to enum
                            string ifcEnumType = CategoryUtil.GetIFCEnumTypeName(exporterIFC, element);
                            elemHnd = IFCInstanceExporter.CreateRoof(file, elemGUID, ownerHistory, elemName, elemDesc, elemType, localPlacement,
                                prodRepHnd, elemId, RoofExporter.GetIFCRoofType(ifcEnumType));
                        }
                        else
                        {
                            return;
                        }

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(elemHnd))
                            return;
                        
                        wrapper.AddElement(elemHnd, setter, null, true);

                        ExporterIFCUtils.CreateCurtainWallPropertySet(exporterIFC, element, wrapper);
                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, wrapper);
                        ICollection<IFCAnyHandle> relatedElementIds = curtainWallSubWrapper.GetAllObjects();
                        if (relatedElementIds.Count > 0)
                        {
                            string guid = ExporterIFCUtils.CreateSubElementGUID(element, (int)IFCCurtainWallSubElements.RelAggregates);
                            HashSet<IFCAnyHandle> relatedElementIdSet = new HashSet<IFCAnyHandle>(relatedElementIds);
                            IFCInstanceExporter.CreateRelAggregates(file, guid, ownerHistory, null, null, elemHnd, relatedElementIdSet);
                        }
                        exporterIFC.RegisterSpaceBoundingElementHandle(elemHnd, element.Id, ElementId.InvalidElementId);
                    }
                }
                finally
                {
                    if (setter != null)
                        setter.Dispose();
                }
            }
        }
        /// <summary>
        /// Exports a family instance as a mapped item.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="familyInstance">
        /// The family instance to be exported.
        /// </param>
        /// <param name="exportType">
        /// The export type.
        /// </param>
        /// <param name="ifcEnumType">
        /// The string value represents the IFC type.
        /// </param>
        /// <param name="wrapper">
        /// The IFCProductWrapper.
        /// </param>
        /// <param name="overrideLevelId">
        /// The level id.
        /// </param>
        /// <param name="range">
        /// The range of this family instance to be exported.
        /// </param>
        public static void ExportFamilyInstanceAsMappedItem(ExporterIFC exporterIFC,
           FamilyInstance familyInstance, IFCExportType exportType, string ifcEnumType,
           IFCProductWrapper wrapper, ElementId overrideLevelId, UV range)
        {
            Document doc = familyInstance.Document;
            IFCFile file = exporterIFC.GetFile();

            FamilySymbol familySymbol = ExporterIFCUtils.GetOriginalSymbol(familyInstance);
            if (familySymbol == null)
                return;

            IFCProductWrapper familyProductWrapper = IFCProductWrapper.Create(wrapper);
            double scale = exporterIFC.LinearScale;

            IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

            HostObject hostElement = familyInstance.Host as HostObject; //hostElement could be null
            ElementId categoryId = CategoryUtil.GetSafeCategoryId(familySymbol);

            //string emptyString = "";
            string familyName = familySymbol.Name;
            IFCLabel objectType = IFCLabel.Create(familyName);

            // A Family Instance can have its own copy of geometry, or use the symbol's copy with a transform.
            // The routine below tells us whether to use the Instance's copy or the Symbol's copy.
            bool useInstanceGeometry = ExporterIFCUtils.UsesInstanceGeometry(familyInstance);

            IList<IFCExtrusionData> cutPairOpeningsForColumns = new List<IFCExtrusionData>();
            IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData();

            Transform trf = familyInstance.GetTransform();

            // Extra information if we are exporting a door or a window.
            IFCDoorWindowInfo doorWindowInfo = null;
            if (exportType == IFCExportType.ExportDoorType)
                doorWindowInfo = IFCDoorWindowInfo.CreateDoorInfo(exporterIFC, familyInstance, familySymbol, hostElement, overrideLevelId, trf);
            else if (exportType == IFCExportType.ExportWindowType)
                doorWindowInfo = IFCDoorWindowInfo.CreateWindowInfo(exporterIFC, familyInstance, familySymbol, hostElement, overrideLevelId, trf);

            IFCTypeInfo typeInfo = new IFCTypeInfo();
            XYZ extraOffset = XYZ.Zero;

            bool flipped = doorWindowInfo != null ? doorWindowInfo.IsSymbolFlipped : false;
            IFCTypeInfo currentTypeInfo = exporterIFC.FindType(familySymbol.Id, flipped);
            bool found = currentTypeInfo.IsValid();

            Family family = familySymbol.Family;

            // TODO: this code to be removed by ExtrusionAnalyzer code.
            bool trySpecialColumnCreation = ((exportType == IFCExportType.ExportColumnType) && (!family.IsInPlace));

            // We will create a new mapped type if:
            // 1.  We are exporting part of a column or in-place wall (range != null), OR
            // 2.  We are using the instance's copy of the geometry (that it, it has unique geometry), OR
            // 3.  We haven't already created the type.
            bool creatingType = ((range != null) || useInstanceGeometry || !found);
            if (creatingType)
            {
                IFCAnyHandle bodyRepresentation = IFCAnyHandle.Create();
                IFCAnyHandle planRepresentation = IFCAnyHandle.Create();

                // If we are using the instance geometry, ignore the transformation.
                if (useInstanceGeometry)
                    trf = Transform.Identity;

                // TODO: this code to be removed by ExtrusionAnalyzer code.
                if (trySpecialColumnCreation)
                {
                    XYZ rangeOffset = trf.Origin;
                    IFCFamilyInstanceExtrusionExportResults results;
                    if (range != null)
                    {
                        results = ExporterIFCUtils.ExportFamilyInstanceAsExtrusion(exporterIFC, familyInstance, useInstanceGeometry, range, overrideLevelId, extraParams);
                    }
                    else
                    {
                        results = ExporterIFCUtils.ExportFamilyInstanceAsExtrusion(exporterIFC, familyInstance, useInstanceGeometry, overrideLevelId, extraParams);
                    }
                    bodyRepresentation = results.GetExtrusionHandle();
                    extraOffset = results.ExtraOffset;
                    cutPairOpeningsForColumns = results.GetCutPairOpenings();

                    if (bodyRepresentation.HasValue)
                    {
                        typeInfo.MaterialId = results.MaterialId;
                        // add in level for real columns, not in-place ones.
                        Element actualLevel =
                           (overrideLevelId == ElementId.InvalidElementId) ? familyInstance.Level : doc.get_Element(overrideLevelId);
                        if (actualLevel != null)
                        {
                            IFCLevelInfo levelInfo = exporterIFC.GetLevelInfo(actualLevel.Id);
                            double nonStoryLevelOffset = LevelUtil.GetNonStoryLevelOffsetIfAny(exporterIFC, actualLevel as Level);
                            if (range != null)
                            {
                                rangeOffset = new XYZ(rangeOffset.X, rangeOffset.Y, levelInfo.Elevation + nonStoryLevelOffset);
                            }
                        }
                    }

                    rangeOffset += extraOffset;
                    trf.Origin = rangeOffset;
                }

                Transform doorWindowTrf = Transform.Identity;
                IFCAnyHandle dummyPlacement = IFCAnyHandle.Create();
                if (doorWindowInfo != null)
                {
                    doorWindowTrf = ExporterIFCUtils.GetTransformForDoorOrWindow(familyInstance, familySymbol, doorWindowInfo);
                }
                else
                {
                    dummyPlacement = file.CreateLocalPlacement(IFCAnyHandle.Create(), file.CreateAxis2Placement3D());
                    extraParams.SetLocalPlacement(dummyPlacement);
                }

                bool needToCreate2d = (!exporterIFC.ExportAs2x2);
                bool needToCreate3d = (!bodyRepresentation.HasValue);

                if (needToCreate2d || needToCreate3d)
                {
                    using (IFCTransformSetter trfSetter = IFCTransformSetter.Create())
                    {
                        if (doorWindowInfo != null)
                        {
                            trfSetter.Initialize(exporterIFC, doorWindowTrf);
                        }

                        Options options = new Options();
                        GeometryElement exportGeometry =
                           useInstanceGeometry ? familyInstance.get_Geometry(options) : familySymbol.get_Geometry(options);
                        if (exportGeometry == null)
                            return;

                        if (needToCreate3d)
                        {
                            IFCSolidMeshGeometryInfo solidMeshInfo;

                            if (range == null)
                                solidMeshInfo = ExporterIFCUtils.GetSolidMeshGeometry(exporterIFC, exportGeometry, Transform.Identity);
                            else
                                solidMeshInfo = ExporterIFCUtils.GetClippedSolidMeshGeometry(exporterIFC, range, exportGeometry);

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

                            bool tryToExportAsExtrusion = (!exporterIFC.ExportAs2x2 || (exportType == IFCExportType.ExportColumnType));

                            if (exportType == IFCExportType.ExportColumnType)
                            {
                                extraParams.PossibleExtrusionAxes = IFCExtrusionAxes.TryZ;
                            }
                            else
                            {
                                extraParams.PossibleExtrusionAxes = IFCExtrusionAxes.TryXYZ;
                            }

                            if (solids.Count > 0 || polyMeshes.Count > 0)
                            {
                                bodyRepresentation = BodyExporter.ExportBody(familyInstance.Document.Application, exporterIFC, categoryId, solids, polyMeshes,
                                    tryToExportAsExtrusion, extraParams);
                                typeInfo.MaterialId = BodyExporter.GetBestMaterialIdForGeometry(solids, polyMeshes);
                            }
                            else
                            {
                                IList<GeometryObject> exportedGeometries = new List<GeometryObject>();
                                exportedGeometries.Add(exportGeometry);
                                bodyRepresentation = BodyExporter.ExportBody(familyInstance.Document.Application, exporterIFC, categoryId, exportedGeometries,
                                   tryToExportAsExtrusion, extraParams);
                            }

                            if (!bodyRepresentation.HasValue)
                            {
                                extraParams.ClearOpenings();
                                return;
                            }
                        }

                        // if exporting IFC2x3 (or later), export 2D plan rep of family (if it exists).
                        if (needToCreate2d)
                        {
                            HashSet<IFCAnyHandle> curveSet = new HashSet<IFCAnyHandle>();
                            {
                                Transform planeTrf = doorWindowTrf.Inverse;
                                Plane plane = new Plane(planeTrf.get_Basis(0), planeTrf.get_Basis(1), planeTrf.Origin);
                                XYZ projDir = new XYZ(0, 0, 1);

                                IFCGeometryInfo IFCGeometryInfo = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, plane, projDir, true);
                                ExporterIFCUtils.CollectGeometryInfo(exporterIFC, IFCGeometryInfo, exportGeometry, planeTrf.Origin, false);

                                IList<IFCAnyHandle> curves = IFCGeometryInfo.GetCurves();
                                foreach (IFCAnyHandle curve in curves)
                                    curveSet.Add(curve);

                                if (curveSet.Count > 0)
                                {
                                    IFCAnyHandle contextOfItems2d = exporterIFC.Get2DContextHandle();
                                    IFCAnyHandle curveRepresentationItem = file.CreateGeometricSet(curveSet);
                                    HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
                                    bodyItems.Add(curveRepresentationItem);
                                    planRepresentation = RepresentationUtil.CreateGeometricSetRep(exporterIFC, categoryId, "Annotation",
                                       contextOfItems2d, bodyItems);
                                }
                            }
                        }
                    }
                }

                if (doorWindowInfo != null)
                {
                    typeInfo.SetStyleTransform(doorWindowTrf.Inverse);
                }
                else
                {
                    if (!MathUtil.IsAlmostZero(extraOffset.DotProduct(extraOffset)))
                    {
                        Transform newTransform = typeInfo.GetStyleTransform();
                        XYZ newOrig = newTransform.Origin + extraOffset;
                        newTransform.Origin = newOrig;
                        typeInfo.SetStyleTransform(newTransform);
                    }
                    typeInfo.SetStyleTransform(ExporterIFCUtils.GetUnscaledTransform(exporterIFC, extraParams.GetLocalPlacement()));
                }

                IFCLabel descriptionOpt = IFCLabel.Create();
                IFCLabel applicableOccurrenceOpt = IFCLabel.Create();

                IFCAnyHandle origin = file.CreateAxis2Placement3D();
                IFCAnyHandle repMap2dHnd = IFCAnyHandle.Create();
                IFCAnyHandle repMap3dHnd = file.CreateRepresentationMap(origin, bodyRepresentation);

                IList<IFCAnyHandle> repMapList = new List<IFCAnyHandle>();
                repMapList.Add(repMap3dHnd);
                if (planRepresentation.HasValue)
                {
                    repMap2dHnd = file.CreateRepresentationMap(origin, planRepresentation);
                    repMapList.Add(repMap2dHnd);
                }

                // for Door, Window
                bool paramTakesPrecedence = false; // For Revit, this is currently always false.
                bool sizeable = false;

                // for many
                HashSet<IFCAnyHandle> propertySets = new HashSet<IFCAnyHandle>();

                IFCLabel guid = IFCLabel.CreateGUID(familySymbol);
                IFCLabel symIdAsLabel = NamingUtil.CreateIFCElementId(familySymbol);

                // This covers many generic types.  If we can't find it in the list here, do custom exports.
                IFCAnyHandle typeStyle = FamilyExporterUtil.ExportGenericType(file, exportType, ifcEnumType, guid,
                   ownerHistory, objectType, descriptionOpt, applicableOccurrenceOpt, propertySets, repMapList, symIdAsLabel, objectType,
                   familyInstance, familySymbol);

                // Cover special cases not covered above.
                if (!typeStyle.HasValue)
                {
                    switch (exportType)
                    {
                        case IFCExportType.ExportColumnType:
                            {
                                // If we are using the instance GRep, then we have to create a generic GUID for the
                                // column type, as they share the same ElementId.
                                IFCLabel colGUID = IFCLabel.Create();
                                IFCLabel colElemId = IFCLabel.Create();

                                if (useInstanceGeometry)
                                {
                                    colGUID = IFCLabel.CreateGUID();
                                    colElemId = NamingUtil.CreateIFCElementId(familyInstance);
                                }
                                else
                                {
                                    colGUID = guid;
                                    colElemId = NamingUtil.CreateIFCElementId(familySymbol);
                                }

                                string columnType = "Column";
                                typeStyle = file.CreateColumnType(columnType, colGUID, ownerHistory, objectType,
                                   descriptionOpt, applicableOccurrenceOpt, propertySets, repMapList, colElemId,
                                   objectType, familyInstance, familySymbol);

                                break;
                            }
                        case IFCExportType.ExportDoorType:
                            {
                                string constructionType = string.Empty;
                                ParameterUtil.GetStringValueFromElementOrSymbol(familyInstance, "Construction", out constructionType);

                                IFCAnyHandle doorLining = DoorWindowUtil.CreateDoorLiningProperties(exporterIFC, familyInstance);
                                if (doorLining.HasValue)
                                    propertySets.Add(doorLining);

                                IList<IFCAnyHandle> doorPanels = DoorWindowUtil.CreateDoorPanelProperties(exporterIFC, doorWindowInfo,
                                   familyInstance);
                                propertySets.UnionWith(doorPanels);

                                IFCLabel doorStyleGUID = IFCLabel.CreateGUID();
                                IFCLabel doorStyleElemId = NamingUtil.CreateIFCElementId(familyInstance);
                                typeStyle = file.CreateDoorStyle(doorStyleGUID, ownerHistory, objectType,
                                   descriptionOpt, applicableOccurrenceOpt, propertySets, repMapList, doorStyleElemId,
                                   doorWindowInfo.DoorOperationType, constructionType, paramTakesPrecedence, sizeable);
                                break;
                            }
                        case IFCExportType.ExportSystemFurnitureElementType:
                            {
                                IFCLabel furnitureId = NamingUtil.CreateIFCElementId(familyInstance);
                                typeStyle = file.CreateSystemFurnitureElementType(guid, ownerHistory, objectType,
                                   descriptionOpt, applicableOccurrenceOpt, propertySets, repMapList, furnitureId,
                                   objectType);
                                break;
                            }
                        case IFCExportType.ExportWindowType:
                            {
                                IFCWindowStyleOperation operationType = DoorWindowUtil.GetIFCWindowStyleOperation(familySymbol);
                                string constructionType = DoorWindowUtil.GetIFCWindowStyleConstruction(familyInstance, "");

                                IFCAnyHandle windowLining = DoorWindowUtil.CreateWindowLiningProperties(exporterIFC, familyInstance, descriptionOpt);
                                if (windowLining.HasValue)
                                    propertySets.Add(windowLining);

                                IList<IFCAnyHandle> windowPanels =
                                   DoorWindowUtil.CreateWindowPanelProperties(exporterIFC, familyInstance, descriptionOpt);
                                propertySets.UnionWith(windowPanels);

                                IFCLabel windowStyleGUID = IFCLabel.CreateGUID();
                                IFCLabel windowStyleElemId = NamingUtil.CreateIFCElementId(familyInstance);
                                typeStyle = file.CreateWindowStyle(windowStyleGUID, ownerHistory, objectType,
                                   descriptionOpt, applicableOccurrenceOpt, propertySets, repMapList, windowStyleElemId,
                                   operationType, constructionType, paramTakesPrecedence, sizeable);
                                break;
                            }
                        case IFCExportType.ExportBuildingElementProxy:
                        default:
                            {
                                typeInfo.Set2DMapHandle(repMap2dHnd);
                                typeInfo.Set3DMapHandle(repMap3dHnd);
                                break;
                            }
                    }
                }

                typeInfo.SetStyle(typeStyle);

                // Transfer extraParams information for certain types.
                if (typeStyle.HasValue)
                {
                    if (((exportType == IFCExportType.ExportColumnType) && trySpecialColumnCreation) ||
                       (exportType == IFCExportType.ExportMemberType))
                    {
                        typeInfo.ScaledArea = extraParams.ScaledArea;
                        typeInfo.ScaledDepth = extraParams.ScaledLength;
                        typeInfo.ScaledInnerPerimeter = extraParams.ScaledInnerPerimeter;
                        typeInfo.ScaledOuterPerimeter = extraParams.ScaledOuterPerimeter;
                    }
                }
            }
            else if (!creatingType && (trySpecialColumnCreation))
            {
                // still need to modify instance trf for columns.
                trf.Origin += GetLevelOffsetForExtrudedColumns(exporterIFC, familyInstance, overrideLevelId, extraParams);
            }

            if (found && !typeInfo.GetStyle().HasValue)
            {
                typeInfo = currentTypeInfo;
            }

            // we'll pretend we succeeded, but we'll do nothing.
            if (!typeInfo.GetStyle().HasValue && !typeInfo.Get2DMapHandle().HasValue && !typeInfo.Get3DMapHandle().HasValue)
                return;

            // add to the map, as long as we are not using range, not using instance geometry, and don't have extra openings.
            if ((range == null) && !useInstanceGeometry && (extraParams.GetOpenings().Count == 0))
                exporterIFC.AddType(familySymbol.Id, flipped, typeInfo);

            Transform oldTrf = new Transform(trf);
            XYZ scaledMapOrigin = XYZ.Zero;

            trf = trf.Multiply(typeInfo.GetStyleTransform());

            // create instance.  
            IList<IFCAnyHandle> shapeReps = new List<IFCAnyHandle>();
            {
                IFCAnyHandle contextOfItems2d = exporterIFC.Get2DContextHandle();
                IFCAnyHandle contextOfItems3d = exporterIFC.Get3DContextHandle();

                // for proxies, we store the IfcRepresentationMap directly since there is no style.
                IList<IFCAnyHandle> repMapList = IFCGeometryUtils.GetRepresentationMaps(typeInfo.GetStyle());
                int numReps = repMapList.Count;

                IFCAnyHandle repMap2dHnd = typeInfo.Get2DMapHandle();
                IFCAnyHandle repMap3dHnd = typeInfo.Get3DMapHandle();
                if (!repMap3dHnd.HasValue && (numReps > 0))
                    repMap3dHnd = repMapList[0];
                if (!repMap2dHnd.HasValue && (numReps > 1))
                    repMap2dHnd = repMapList[1];

                if (repMap3dHnd.HasValue)
                {
                    HashSet<IFCAnyHandle> representations = new HashSet<IFCAnyHandle>();
                    representations.Add(ExporterUtil.CreateDefaultMappedItem(file, repMap3dHnd, scaledMapOrigin));
                    IFCAnyHandle shapeRep = RepresentationUtil.CreateBodyMappedItemRep(exporterIFC, categoryId, contextOfItems3d, representations);
                    if (!shapeRep.HasValue)
                        return;
                    shapeReps.Add(shapeRep);
                }

                if (repMap2dHnd.HasValue)
                {
                    HashSet<IFCAnyHandle> representations = new HashSet<IFCAnyHandle>();
                    representations.Add(ExporterUtil.CreateDefaultMappedItem(file, repMap2dHnd, scaledMapOrigin));
                    IFCAnyHandle shapeRep = RepresentationUtil.CreatePlanMappedItemRep(exporterIFC, categoryId, contextOfItems2d, representations);
                    if (!shapeRep.HasValue)
                        return;
                    shapeReps.Add(shapeRep);
                }
            }

            IFCLabel noDescriptionOpt = IFCLabel.Create();
            IFCLabel noNameOpt = IFCLabel.Create();
            IFCAnyHandle rep = file.CreateProductDefinitionShape(noNameOpt, noDescriptionOpt, shapeReps);

            IFCAnyHandle instanceHandle = IFCAnyHandle.Create();
            using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, familyInstance, trf, null, overrideLevelId))
            {
                IFCLabel instanceGUID = IFCLabel.CreateGUID(familyInstance);
                IFCLabel origInstanceName = NamingUtil.CreateIFCName(exporterIFC, -1);
                IFCLabel instanceName = NamingUtil.GetNameOverride(familyInstance, origInstanceName);
                IFCLabel instanceDescription = NamingUtil.GetDescriptionOverride(familyInstance, noDescriptionOpt);
                IFCLabel instanceObjectType = NamingUtil.GetObjectTypeOverride(familyInstance, objectType);
                IFCLabel instanceElemId = NamingUtil.CreateIFCElementId(familyInstance);

                IFCAnyHandle localPlacement = setter.GetPlacement();
                instanceHandle = FamilyExporterUtil.ExportGenericInstance(exportType, exporterIFC, familyInstance,
                   wrapper, setter, extraParams, instanceGUID, ownerHistory, instanceName, instanceDescription, instanceObjectType,
                   rep, instanceElemId);

                switch (exportType)
                {
                    case IFCExportType.ExportColumnType:
                        {
                            IFCAnyHandle placementToUse = localPlacement;
                            if (!useInstanceGeometry)
                            {
                                Transform openingTrf = new Transform(oldTrf);
                                Transform extraRot = new Transform(oldTrf);
                                extraRot.Origin = XYZ.Zero;
                                openingTrf = openingTrf.Multiply(extraRot);
                                openingTrf = openingTrf.Multiply(typeInfo.GetStyleTransform());

                                IFCAnyHandle openingRelativePlacement = file.CreateAxis2Placement3D(openingTrf.Origin * scale,
                                   openingTrf.get_Basis(2), openingTrf.get_Basis(0));
                                IFCAnyHandle openingPlacement = ExporterUtil.CopyLocalPlacement(file, localPlacement);
                                IFCGeometryUtils.SetRelativePlacement(openingPlacement, openingRelativePlacement);
                                placementToUse = openingPlacement;
                            }

                            OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, familyInstance, cutPairOpeningsForColumns,
                               exporterIFC, placementToUse, setter, wrapper);
                            OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, familyInstance, extraParams, exporterIFC,
                               placementToUse, setter, wrapper);

                            //export Base Quantities.
                            ExporterIFCUtils.CreateBeamColumnBaseQuantities(exporterIFC, instanceHandle, familyInstance, typeInfo);

                            CategoryUtil.CreateMaterialAssociation(doc, exporterIFC, instanceHandle, typeInfo.MaterialId);

                            ExporterIFCUtils.CreateColumnPropertySet(exporterIFC, familyInstance, extraParams, wrapper);
                            break;
                        }
                    case IFCExportType.ExportDoorType:
                    case IFCExportType.ExportWindowType:
                        {
                            double doorHeight = doorWindowInfo.OpeningHeight;
                            if (doorHeight < MathUtil.Eps())
                                doorHeight = GetMinSymbolHeight(familySymbol);
                            double doorWidth = doorWindowInfo.OpeningWidth;
                            if (doorWidth < MathUtil.Eps())
                                doorWidth = GetMinSymbolWidth(familySymbol);

                            IFCMeasureValue height = IFCMeasureValue.Create(doorHeight * scale);
                            IFCMeasureValue width = IFCMeasureValue.Create(doorWidth * scale);

                            if (!doorWindowInfo.GetLocalPlacement().HasValue)
                                doorWindowInfo.SetLocalPlacement(localPlacement);

                            IFCAnyHandle doorWindowOrigLocalPlacement = doorWindowInfo.GetLocalPlacement();
                            Transform relTrf = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(localPlacement, doorWindowOrigLocalPlacement);

                            IFCAnyHandle doorWindowRelativePlacement = file.CreateAxis2Placement3D(relTrf);
                            IFCAnyHandle doorWindowLocalPlacement =
                               file.CreateLocalPlacement(doorWindowOrigLocalPlacement, doorWindowRelativePlacement);
                            if (exportType == IFCExportType.ExportDoorType)
                                instanceHandle = file.CreateDoor(instanceGUID, ownerHistory,
                                   instanceName, instanceDescription, instanceObjectType, doorWindowLocalPlacement,
                                   rep, instanceElemId, height, width);
                            else if (exportType == IFCExportType.ExportWindowType)
                                instanceHandle = file.CreateWindow(instanceGUID, ownerHistory,
                                   instanceName, instanceDescription, instanceObjectType, doorWindowLocalPlacement,
                                   rep, instanceElemId, height, width);
                            wrapper.AddElement(instanceHandle, setter, extraParams, true);

                            exporterIFC.RegisterSpaceBoundingElementHandle(instanceHandle, familyInstance.Id, setter.LevelId);

                            // only necessary when exporting as possible breps.
                            OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, familyInstance, extraParams, exporterIFC,
                               doorWindowLocalPlacement, setter, wrapper);
                            if (exporterIFC.ExportBaseQuantities)
                                ExporterIFCUtils.CreateDoorWindowBaseQuantities(exporterIFC, instanceHandle, (doorHeight * scale), (doorWidth * scale));

                            if (exportType == IFCExportType.ExportDoorType)
                                ExporterIFCUtils.CreateDoorPropertySet(exporterIFC, familyInstance, wrapper);
                            else
                                ExporterIFCUtils.CreateWindowPropertySet(exporterIFC, familyInstance, wrapper);
                            break;
                        }
                    case IFCExportType.ExportMemberType:
                        {
                            OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, familyInstance, extraParams, exporterIFC,
                              localPlacement, setter, wrapper);
                            CategoryUtil.CreateMaterialAssociation(doc, exporterIFC, instanceHandle, typeInfo.MaterialId);

                            //export Base Quantities.
                            ExporterIFCUtils.CreateBeamColumnBaseQuantities(exporterIFC, instanceHandle, familyInstance, typeInfo);
                            // TODO: create PropertySet!
                            //createMemberPropertySet(exporter, pFamInst, pWrapper, extraParams);
                            ExporterIFCUtils.CreateGenericElementPropertySet(exporterIFC, familyInstance, wrapper);
                            break;
                        }
                    case IFCExportType.ExportPlateType:
                        {
                            OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, familyInstance, extraParams, exporterIFC,
                              localPlacement, setter, wrapper);
                            CategoryUtil.CreateMaterialAssociation(doc, exporterIFC, instanceHandle, typeInfo.MaterialId);

                            // TODO: create PropertySet!
                            //createPlatePropertySet(exporter, pFamInst, pWrapper, extraParams);
                            ExporterIFCUtils.CreateGenericElementPropertySet(exporterIFC, familyInstance, wrapper);
                            break;
                        }
                    case IFCExportType.ExportTransportElementType:
                        {
                            string operationTypeOpt = "";
                            IFCMeasureValue capByWeightOpt = IFCMeasureValue.Create();
                            IFCMeasureValue capByNumOpt = IFCMeasureValue.Create();

                            IFCAnyHandle localPlacementToUse;
                            ElementId roomId = setter.UpdateRoomRelativeCoordinates(familyInstance, out localPlacementToUse);

                            instanceHandle = file.CreateTransportElement(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType,
                               localPlacementToUse, rep, instanceElemId, operationTypeOpt, capByWeightOpt, capByNumOpt,
                               familyInstance, familySymbol);

                            if (roomId == ElementId.InvalidElementId)
                            {
                                wrapper.AddElement(instanceHandle, setter, extraParams, true);
                            }
                            else
                            {
                                exporterIFC.RelateSpatialElement(roomId, instanceHandle);
                                wrapper.AddElement(instanceHandle, setter, extraParams, false);
                            }

                            ExporterIFCUtils.CreateGenericElementPropertySet(exporterIFC, familyInstance, wrapper);
                            break;
                        }
                    case IFCExportType.ExportBuildingElementProxy:
                    default:
                        {
                            bool isBuildingElementProxy = (exportType == IFCExportType.ExportBuildingElementProxy);

                            if (!isBuildingElementProxy)
                            {
                                if (FamilyExporterUtil.IsDistributionControlElementSubType(exportType))
                                {
                                    IFCLabel controlElementId = IFCLabel.Create();
                                    IFCAnyHandle localPlacementToUse;
                                    ElementId roomId = setter.UpdateRoomRelativeCoordinates(familyInstance, out localPlacementToUse);

                                    instanceHandle = file.CreateDistributionControlElement(instanceGUID,
                                       ownerHistory, instanceName, instanceDescription, instanceObjectType,
                                       localPlacement, rep, instanceElemId, controlElementId);

                                    if (roomId == ElementId.InvalidElementId)
                                    {
                                        wrapper.AddElement(instanceHandle, setter, extraParams, true);
                                    }
                                    else
                                    {
                                        exporterIFC.RelateSpatialElement(roomId, instanceHandle);
                                        wrapper.AddElement(instanceHandle, setter, extraParams, false);
                                    }

                                    OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, familyInstance, extraParams, exporterIFC,
                                       localPlacement, setter, wrapper);
                                }
                                else if (!instanceHandle.HasValue)
                                {
                                    isBuildingElementProxy = true;
                                }
                            }

                            if (isBuildingElementProxy)
                            {
                                IFCElementComposition proxyType = IFCElementComposition.Element;
                                IFCAnyHandle localPlacementToUse;
                                ElementId roomId = setter.UpdateRoomRelativeCoordinates(familyInstance, out localPlacementToUse);

                                instanceHandle = file.CreateBuildingElementProxy(instanceGUID,
                                   ownerHistory, instanceName, instanceDescription, instanceObjectType,
                                   localPlacementToUse, rep, instanceElemId, proxyType);

                                if (roomId == ElementId.InvalidElementId)
                                {
                                    wrapper.AddElement(instanceHandle, setter, extraParams, true);
                                }
                                else
                                {
                                    exporterIFC.RelateSpatialElement(roomId, instanceHandle);
                                    wrapper.AddElement(instanceHandle, setter, extraParams, false);
                                }

                                OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, familyInstance, extraParams, exporterIFC,
                                   localPlacement, setter, wrapper);
                            }

                            ExporterIFCUtils.CreateGenericElementPropertySet(exporterIFC, familyInstance, wrapper);
                            break;
                        }
                }

                if (instanceHandle.HasValue)
                {
                    if (doorWindowInfo != null)
                    {
                        if (doorWindowInfo.GetOpening().HasValue)
                        {
                            IFCLabel relGUID = IFCLabel.CreateGUID();
                            file.CreateRelFillsElement(relGUID, ownerHistory, IFCLabel.Create(), IFCLabel.Create(), doorWindowInfo.GetOpening(), instanceHandle);
                        }
                        else if (doorWindowInfo.NeedsOpening)
                        {
                            bool added = doorWindowInfo.SetDelayedFamilyInstance(instanceHandle, localPlacement, doorWindowInfo.AssignedLevelId);
                            if (added)
                                exporterIFC.RegisterDoorWindowForOpeningUpdate(doorWindowInfo);
                            else
                            {
                                // we need to fill a later opening.
                                exporterIFC.RegisterDoorWindowForUncreatedOpening(familyInstance.Id, instanceHandle);
                            }
                        }
                    }

                    if (typeInfo.GetStyle().HasValue)
                        exporterIFC.AddTypeRelation(typeInfo.GetStyle(), instanceHandle);
                }
            }
        }
Beispiel #28
0
        /// <summary>
        /// Exports the top stories of a multistory staircase.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="stair">The stairs element.</param>
        /// <param name="numFlights">The number of flights for a multistory staircase.</param>
        /// <param name="stairHnd">The stairs container handle.</param>
        /// <param name="components">The components handles.</param>
        /// <param name="ecData">The extrusion creation data.</param>
        /// <param name="componentECData">The extrusion creation data for the components.</param>
        /// <param name="materialIds">The materialIds.</param>
        /// <param name="placementSetter">The placement setter.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportMultistoryStair(ExporterIFC exporterIFC, Element stair, int numFlights,
            IFCAnyHandle stairHnd, IList<IFCAnyHandle> components, IList<IFCExtrusionCreationData> componentECData,
            HashSet<ElementId> materialIds, IFCPlacementSetter placementSetter, IFCProductWrapper productWrapper)
        {
            if (numFlights < 2)
                return;

            double heightNonScaled = GetStairsHeight(exporterIFC, stair);
            if (heightNonScaled < MathUtil.Eps())
                return;

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(stairHnd))
                return;

            IFCAnyHandle localPlacement = IFCAnyHandleUtil.GetInstanceAttribute(stairHnd, "ObjectPlacement");
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(localPlacement))
                return;

            IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

            IFCFile file = exporterIFC.GetFile();

            IFCAnyHandle relPlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);
            IFCAnyHandle ptHnd = IFCAnyHandleUtil.GetLocation(relPlacement);
            IList<double> origCoords = IFCAnyHandleUtil.GetCoordinates(ptHnd);

            double scale = exporterIFC.LinearScale;

            ICollection<ElementId> runIds = null;
            ICollection<ElementId> landingIds = null;
            ICollection<ElementId> supportIds = null;

            if (stair is Stairs)
            {
                Stairs stairAsStairs = stair as Stairs;
                runIds = stairAsStairs.GetStairsRuns();
                landingIds = stairAsStairs.GetStairsLandings();
                supportIds = stairAsStairs.GetStairsSupports();
            }

            IList<IFCAnyHandle> stairLocalPlacementHnds = new List<IFCAnyHandle>();
            IList<IFCLevelInfo> levelInfos = new List<IFCLevelInfo>();
            for (int ii = 0; ii < numFlights - 1; ii++)
            {
                double newOffsetScaled = 0.0;
                IFCAnyHandle newLevelHnd = null;
                levelInfos.Add(
                    placementSetter.GetOffsetLevelInfoAndHandle(heightNonScaled * (ii + 1), scale, out newLevelHnd, out newOffsetScaled));
                if (levelInfos[ii] == null)
                    levelInfos[ii] = placementSetter.GetLevelInfo();

                XYZ orig;
                if (ptHnd.HasValue)
                {
                    orig = new XYZ(origCoords[0], origCoords[1], newOffsetScaled);
                }
                else
                {
                    orig = new XYZ(0.0, 0.0, newOffsetScaled);
                }
                IFCAnyHandle relativePlacementHnd = ExporterUtil.CreateAxis2Placement3D(file, orig);
                stairLocalPlacementHnds.Add(IFCInstanceExporter.CreateLocalPlacement(file, newLevelHnd, relativePlacementHnd));
            }

            IList<List<IFCAnyHandle>> newComponents = new List<List<IFCAnyHandle>>();
            for (int ii = 0; ii < numFlights - 1; ii++)
                newComponents.Add(new List<IFCAnyHandle>());

            int compIdx = 0;
            IEnumerator<ElementId> runIter = null;
            if (runIds != null)
            {
                runIter = runIds.GetEnumerator();
                runIter.MoveNext();
            }
            IEnumerator<ElementId> landingIter = null;
            if (landingIds != null)
            {
                landingIter = landingIds.GetEnumerator();
                landingIter.MoveNext();
            }
            IEnumerator<ElementId> supportIter = null;
            if (supportIds != null)
            {
                supportIter = supportIds.GetEnumerator();
                supportIter.MoveNext();
            }

            foreach (IFCAnyHandle component in components)
            {
                string componentName = IFCAnyHandleUtil.GetStringAttribute(component, "Name");
                string componentDescription = IFCAnyHandleUtil.GetStringAttribute(component, "Description");
                string componentObjectType = IFCAnyHandleUtil.GetStringAttribute(component, "ObjectType");
                string componentElementTag = IFCAnyHandleUtil.GetStringAttribute(component, "Tag");
                IFCAnyHandle componentProdRep = IFCAnyHandleUtil.GetInstanceAttribute(component, "Representation");

                IList<string> localComponentNames = new List<string>();
                IList<IFCAnyHandle> componentPlacementHnds = new List<IFCAnyHandle>();

                IFCAnyHandle localLocalPlacement = IFCAnyHandleUtil.GetInstanceAttribute(component, "ObjectPlacement");
                IFCAnyHandle localRelativePlacement =
                    (localLocalPlacement == null) ? null : IFCAnyHandleUtil.GetInstanceAttribute(localLocalPlacement, "RelativePlacement");

                bool isSubStair = component.IsSubTypeOf(IFCEntityType.IfcStair.ToString());
                for (int ii = 0; ii < numFlights - 1; ii++)
                {
                    localComponentNames.Add((componentName == null) ? (ii + 2).ToString() : (componentName + ":" + (ii + 2)));
                    if (isSubStair)
                        componentPlacementHnds.Add(ExporterUtil.CopyLocalPlacement(file, stairLocalPlacementHnds[ii]));
                    else
                        componentPlacementHnds.Add(IFCInstanceExporter.CreateLocalPlacement(file, stairLocalPlacementHnds[ii], localRelativePlacement));
                }

                IList<IFCAnyHandle> localComponentHnds = new List<IFCAnyHandle>();
                if (isSubStair)
                {
                    string componentType = IFCAnyHandleUtil.GetEnumerationAttribute(component, "ShapeType");
                    IFCStairType localStairType = GetIFCStairType(componentType);

                    ElementId catId = CategoryUtil.GetSafeCategoryId(stair);

                    for (int ii = 0; ii < numFlights - 1; ii++)
                    {
                        IFCAnyHandle representationCopy =
                            ExporterUtil.CopyProductDefinitionShape(exporterIFC, stair, catId, componentProdRep);

                        localComponentHnds.Add(IFCInstanceExporter.CreateStair(file, ExporterIFCUtils.CreateGUID(), ownerHistory,
                            localComponentNames[ii], componentDescription, componentObjectType, componentPlacementHnds[ii], representationCopy,
                            componentElementTag, localStairType));
                    }
                }
                else if (IFCAnyHandleUtil.IsSubTypeOf(component, IFCEntityType.IfcStairFlight))
                {
                    Element runElem = (runIter == null) ? stair : stair.Document.GetElement(runIter.Current);
                    Element runElemToUse = (runElem == null) ? stair : runElem;
                    ElementId catId = CategoryUtil.GetSafeCategoryId(runElemToUse);

                    int? numberOfRiser = IFCAnyHandleUtil.GetIntAttribute(component, "NumberOfRiser");
                    int? numberOfTreads = IFCAnyHandleUtil.GetIntAttribute(component, "NumberOfTreads");
                    double? riserHeight = IFCAnyHandleUtil.GetDoubleAttribute(component, "RiserHeight");
                    double? treadLength = IFCAnyHandleUtil.GetDoubleAttribute(component, "TreadLength");

                    for (int ii = 0; ii < numFlights - 1; ii++)
                    {
                        IFCAnyHandle representationCopy =
                            ExporterUtil.CopyProductDefinitionShape(exporterIFC, runElemToUse, catId, componentProdRep);

                        localComponentHnds.Add(IFCInstanceExporter.CreateStairFlight(file, ExporterIFCUtils.CreateGUID(), ownerHistory,
                            localComponentNames[ii], componentDescription, componentObjectType, componentPlacementHnds[ii], representationCopy,
                            componentElementTag, numberOfRiser, numberOfTreads, riserHeight, treadLength));
                    }
                    runIter.MoveNext();
                }
                else if (IFCAnyHandleUtil.IsSubTypeOf(component, IFCEntityType.IfcSlab))
                {
                    string componentType = IFCAnyHandleUtil.GetEnumerationAttribute(component, "PredefinedType");
                    IFCSlabType localLandingType = FloorExporter.GetIFCSlabType(componentType);

                    Element landingElem = (landingIter == null) ? stair : stair.Document.GetElement(landingIter.Current);
                    Element landingElemToUse = (landingElem == null) ? stair : landingElem;
                    ElementId catId = CategoryUtil.GetSafeCategoryId(landingElemToUse);

                    for (int ii = 0; ii < numFlights - 1; ii++)
                    {
                        IFCAnyHandle representationCopy =
                            ExporterUtil.CopyProductDefinitionShape(exporterIFC, landingElemToUse, catId, componentProdRep);

                        localComponentHnds.Add(IFCInstanceExporter.CreateSlab(file, ExporterIFCUtils.CreateGUID(), ownerHistory,
                            localComponentNames[ii], componentDescription, componentObjectType, componentPlacementHnds[ii], representationCopy,
                            componentElementTag, localLandingType));
                    }

                    landingIter.MoveNext();
                }
                else if (IFCAnyHandleUtil.IsSubTypeOf(component, IFCEntityType.IfcMember))
                {
                    Element supportElem = (supportIter == null) ? stair : stair.Document.GetElement(supportIter.Current);
                    Element supportElemToUse = (supportElem == null) ? stair : supportElem;
                    ElementId catId = CategoryUtil.GetSafeCategoryId(supportElemToUse);

                    IFCAnyHandle memberType = (supportElemToUse != stair) ? GetMemberTypeHandle(exporterIFC, supportElemToUse) : null;

                    for (int ii = 0; ii < numFlights - 1; ii++)
                    {
                        IFCAnyHandle representationCopy =
                        ExporterUtil.CopyProductDefinitionShape(exporterIFC, supportElemToUse, catId, componentProdRep);

                        localComponentHnds.Add(IFCInstanceExporter.CreateMember(file, ExporterIFCUtils.CreateGUID(), ownerHistory,
                            localComponentNames[ii], componentDescription, componentObjectType, componentPlacementHnds[ii], representationCopy,
                            componentElementTag));

                        if (memberType != null)
                            ExporterCacheManager.TypeRelationsCache.Add(memberType, localComponentHnds[ii]);
                    }

                    supportIter.MoveNext();
                }

                for (int ii = 0; ii < numFlights - 1; ii++)
                {
                    if (localComponentHnds[ii] != null)
                    {
                        newComponents[ii].Add(localComponentHnds[ii]);
                        productWrapper.AddElement(localComponentHnds[ii], levelInfos[ii], componentECData[compIdx], false);
                    }
                }
                compIdx++;
            }

            // finally add a copy of the container.
            IList<IFCAnyHandle> stairCopyHnds = new List<IFCAnyHandle>();
            for (int ii = 0; ii < numFlights - 1; ii++)
            {
                string stairName = IFCAnyHandleUtil.GetStringAttribute(stairHnd, "Name");
                string stairObjectType = IFCAnyHandleUtil.GetStringAttribute(stairHnd, "ObjectType");
                string stairDescription = IFCAnyHandleUtil.GetStringAttribute(stairHnd, "Description");
                string stairElementTag = IFCAnyHandleUtil.GetStringAttribute(stairHnd, "Tag");
                string stairTypeAsString = IFCAnyHandleUtil.GetEnumerationAttribute(stairHnd, "ShapeType");
                IFCStairType stairType = GetIFCStairType(stairTypeAsString);

                string containerStairName = stairName + ":" + (ii + 2);
                stairCopyHnds.Add(IFCInstanceExporter.CreateStair(file, ExporterIFCUtils.CreateGUID(), ownerHistory,
                    containerStairName, stairDescription, stairObjectType, stairLocalPlacementHnds[ii], null, stairElementTag, stairType));

                productWrapper.AddElement(stairCopyHnds[ii], levelInfos[ii], null, LevelUtil.AssociateElementToLevel(stair));
            }

            for (int ii = 0; ii < numFlights - 1; ii++)
            {
                StairRampContainerInfo stairRampInfo = new StairRampContainerInfo(stairCopyHnds[ii], newComponents[ii],
                    stairLocalPlacementHnds[ii]);
                ExporterCacheManager.StairRampContainerInfoCache.AppendStairRampContainerInfo(stair.Id, stairRampInfo);
                CategoryUtil.CreateMaterialAssociations(stair.Document, exporterIFC, stairCopyHnds[ii], materialIds);
            }
        }
        /// <summary>
        /// Exports mullion.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="mullion">
        /// The mullion object.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="localPlacement">
        /// The local placement handle.
        /// </param>
        /// <param name="extraParams">
        /// The extrusion creation data.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, Mullion mullion, GeometryElement geometryElement,
           IFCAnyHandle localPlacement, IFCExtrusionCreationData extraParams, IFCPlacementSetter setter, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            ElementId catId = CategoryUtil.GetSafeCategoryId(mullion);


            IFCSolidMeshGeometryInfo solidMeshInfo = ExporterIFCUtils.GetSolidMeshGeometry(exporterIFC, geometryElement, Transform.Identity);
            IList<Solid> solids = solidMeshInfo.GetSolids();
            IList<Mesh> polyMeshes = solidMeshInfo.GetMeshes();

            bool tryToExportAsExtrusion = true;
            if (solids.Count != 1 || polyMeshes.Count != 0)
                tryToExportAsExtrusion = false;

            IFCAnyHandle shapeRep = BodyExporter.ExportBody(mullion.Document.Application, exporterIFC, catId, solids, polyMeshes, tryToExportAsExtrusion, extraParams);
            IList<IFCAnyHandle> shapeReps = new List<IFCAnyHandle>();
            shapeReps.Add(shapeRep);
            IFCAnyHandle repHnd = file.CreateProductDefinitionShape(IFCLabel.Create(), IFCLabel.Create(), shapeReps);

            IFCLabel elemGUID = IFCLabel.CreateGUID(mullion);
            IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
            IFCLabel elemObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, mullion);
            IFCLabel elemId = NamingUtil.CreateIFCElementId(mullion);
            //IFCLabel elemType = IFCLabel.Create("MULLION");

            IFCAnyHandle mullionHnd = file.CreateMember(elemGUID, ownerHistory, elemObjectType, IFCLabel.Create(), elemObjectType,
               localPlacement, repHnd, elemId);
            productWrapper.AddElement(mullionHnd, setter, extraParams, true);
        }
Beispiel #30
0
        /// <summary>
        /// Exports a staircase to IfcStair, composing into separate runs and landings.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="ifcEnumType">The stairs type.</param>
        /// <param name="stair">The stairs element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="numFlights">The number of flights for a multistory staircase.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportStairsAsContainer(ExporterIFC exporterIFC, string ifcEnumType, Stairs stair, GeometryElement geometryElement,
            int numFlights, IFCProductWrapper productWrapper)
        {
            if (stair == null || geometryElement == null)
                return;

            Document doc = stair.Document;
            Autodesk.Revit.ApplicationServices.Application app = doc.Application;
            IFCFile file = exporterIFC.GetFile();
            Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions();
            ElementId categoryId = CategoryUtil.GetSafeCategoryId(stair);

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, stair))
                {
                    HashSet<ElementId> materialIds = new HashSet<ElementId>();

                    List<IFCAnyHandle> componentHandles = new List<IFCAnyHandle>();
                    IList<IFCExtrusionCreationData> componentExtrusionData = new List<IFCExtrusionCreationData>();

                    IFCAnyHandle contextOfItemsFootPrint = exporterIFC.Get3DContextHandle("FootPrint");

                    Transform trf = ExporterIFCUtils.GetUnscaledTransform(exporterIFC, placementSetter.GetPlacement());
                    Plane boundaryPlane = new Plane(trf.BasisX, trf.BasisY, trf.Origin);
                    XYZ boundaryProjDir = trf.BasisZ;

                    IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                    string stairGUID = ExporterIFCUtils.CreateGUID(stair);
                    string origStairName = exporterIFC.GetName();
                    string stairName = NamingUtil.GetNameOverride(stair, origStairName);
                    string stairDescription = NamingUtil.GetDescriptionOverride(stair, null);
                    string stairObjectType = NamingUtil.GetObjectTypeOverride(stair, NamingUtil.CreateIFCObjectName(exporterIFC, stair));
                    IFCAnyHandle stairLocalPlacement = placementSetter.GetPlacement();
                    string stairElementTag = NamingUtil.CreateIFCElementId(stair);
                    IFCStairType stairType = GetIFCStairType(ifcEnumType);

                    IFCAnyHandle stairContainerHnd = IFCInstanceExporter.CreateStair(file, stairGUID, ownerHistory, stairName,
                        stairDescription, stairObjectType, stairLocalPlacement, null, stairElementTag, stairType);
                    productWrapper.AddElement(stairContainerHnd, placementSetter.GetLevelInfo(), null, LevelUtil.AssociateElementToLevel(stair));

                    // Get List of runs to export their geometry.
                    ICollection<ElementId> runIds = stair.GetStairsRuns();
                    int index = 0;
                    foreach (ElementId runId in runIds)
                    {
                        index++;
                        StairsRun run = doc.GetElement(runId) as StairsRun;

                        using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                        {
                            ecData.AllowVerticalOffsetOfBReps = false;
                            ecData.SetLocalPlacement(placementSetter.GetPlacement());
                            ecData.ReuseLocalPlacement = false;

                            GeometryElement runGeometryElement = run.get_Geometry(geomOptions);

                            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                            BodyData bodyData = BodyExporter.ExportBody(app, exporterIFC, run, categoryId, runGeometryElement,
                                bodyExporterOptions, ecData);

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

                            foreach (ElementId materialId in bodyData.MaterialIds)
                                materialIds.Add(materialId);

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

                            Transform runBoundaryTrf = trf.Multiply(bodyData.BrepOffsetTransform);
                            Plane runBoundaryPlane = new Plane(runBoundaryTrf.BasisX, runBoundaryTrf.BasisY, runBoundaryTrf.Origin);
                            XYZ runBoundaryProjDir = runBoundaryTrf.BasisZ;

                            CurveLoop boundary = run.GetFootprintBoundary();
                            IFCAnyHandle boundaryHnd = ExporterIFCUtils.CreateCurveFromCurveLoop(exporterIFC, boundary,
                                runBoundaryPlane, runBoundaryProjDir);
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(boundaryHnd))
                            {
                                HashSet<IFCAnyHandle> geomSelectSet = new HashSet<IFCAnyHandle>();
                                geomSelectSet.Add(boundaryHnd);

                                HashSet<IFCAnyHandle> boundaryItems = new HashSet<IFCAnyHandle>();
                                boundaryItems.Add(IFCInstanceExporter.CreateGeometricSet(file, geomSelectSet));

                                IFCAnyHandle boundaryRep = RepresentationUtil.CreateGeometricSetRep(exporterIFC, run, categoryId, "FootPrint",
                                    contextOfItemsFootPrint, boundaryItems);
                                reps.Add(boundaryRep);
                            }

                            CurveLoop walkingLine = run.GetStairsPath();
                            IFCAnyHandle walkingLineHnd = ExporterIFCUtils.CreateCurveFromCurveLoop(exporterIFC, walkingLine,
                                runBoundaryPlane, runBoundaryProjDir);
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(walkingLineHnd))
                            {
                                HashSet<IFCAnyHandle> geomSelectSet = new HashSet<IFCAnyHandle>();
                                geomSelectSet.Add(walkingLineHnd);

                                HashSet<IFCAnyHandle> walkingLineItems = new HashSet<IFCAnyHandle>();
                                walkingLineItems.Add(IFCInstanceExporter.CreateGeometricSet(file, geomSelectSet));

                                IFCAnyHandle walkingLineRep = RepresentationUtil.CreateGeometricSetRep(exporterIFC, run, categoryId, "Axis",
                                    contextOfItemsFootPrint, walkingLineItems);
                                reps.Add(walkingLineRep);
                            }

                            IFCAnyHandle representation = IFCInstanceExporter.CreateProductDefinitionShape(exporterIFC.GetFile(), null, null, reps);

                            string runGUID = ExporterIFCUtils.CreateGUID(run);
                            string origRunName = origStairName + " Run " + index;
                            string runName = NamingUtil.GetNameOverride(run, origRunName);
                            string runDescription = NamingUtil.GetDescriptionOverride(run, stairDescription);
                            string runObjectType = NamingUtil.GetObjectTypeOverride(run, stairObjectType);
                            IFCAnyHandle runLocalPlacement = ecData.GetLocalPlacement();
                            string runElementTag = NamingUtil.CreateIFCElementId(run);

                            IFCAnyHandle stairFlightHnd = IFCInstanceExporter.CreateStairFlight(file, runGUID, ownerHistory,
                                runName, runDescription, runObjectType, runLocalPlacement, representation, runElementTag,
                                run.ActualRisersNumber, run.ActualTreadsNumber, stair.ActualRiserHeight, stair.ActualTreadDepth);

                            componentHandles.Add(stairFlightHnd);
                            componentExtrusionData.Add(ecData);

                            productWrapper.AddElement(stairFlightHnd, placementSetter.GetLevelInfo(), ecData, false);

                            ExporterCacheManager.HandleToElementCache.Register(stairFlightHnd, run.Id);
                        }
                    }

                    // Get List of landings to export their geometry.
                    ICollection<ElementId> landingIds = stair.GetStairsLandings();
                    index = 0;
                    foreach (ElementId landingId in landingIds)
                    {
                        index++;
                        StairsLanding landing = doc.GetElement(landingId) as StairsLanding;

                        using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                        {
                            ecData.AllowVerticalOffsetOfBReps = false;
                            ecData.SetLocalPlacement(placementSetter.GetPlacement());
                            ecData.ReuseLocalPlacement = false;

                            GeometryElement landingGeometryElement = landing.get_Geometry(geomOptions);

                            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                            BodyData bodyData = BodyExporter.ExportBody(app, exporterIFC, landing, categoryId, landingGeometryElement,
                                bodyExporterOptions, ecData);

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

                            foreach (ElementId materialId in bodyData.MaterialIds)
                                materialIds.Add(materialId);

                            // create Boundary rep.
                            IList<IFCAnyHandle> reps = new List<IFCAnyHandle>();
                            reps.Add(bodyRep);

                            Transform landingBoundaryTrf = trf.Multiply(bodyData.BrepOffsetTransform);
                            Plane landingBoundaryPlane = new Plane(landingBoundaryTrf.BasisX, landingBoundaryTrf.BasisY, landingBoundaryTrf.Origin);
                            XYZ landingBoundaryProjDir = landingBoundaryTrf.BasisZ;

                            CurveLoop boundary = landing.GetFootprintBoundary();
                            IFCAnyHandle boundaryHnd = ExporterIFCUtils.CreateCurveFromCurveLoop(exporterIFC, boundary,
                                landingBoundaryPlane, landingBoundaryProjDir);
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(boundaryHnd))
                            {
                                HashSet<IFCAnyHandle> geomSelectSet = new HashSet<IFCAnyHandle>();
                                geomSelectSet.Add(boundaryHnd);

                                HashSet<IFCAnyHandle> boundaryItems = new HashSet<IFCAnyHandle>();
                                boundaryItems.Add(IFCInstanceExporter.CreateGeometricSet(file, geomSelectSet));

                                IFCAnyHandle boundaryRep = RepresentationUtil.CreateGeometricSetRep(exporterIFC, landing, categoryId, "FootPrint",
                                    contextOfItemsFootPrint, boundaryItems);
                                reps.Add(boundaryRep);
                            }

                            CurveLoop walkingLine = landing.GetStairsPath();
                            IFCAnyHandle walkingLineHnd = ExporterIFCUtils.CreateCurveFromCurveLoop(exporterIFC, walkingLine,
                                landingBoundaryPlane, landingBoundaryProjDir);
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(walkingLineHnd))
                            {
                                HashSet<IFCAnyHandle> geomSelectSet = new HashSet<IFCAnyHandle>();
                                geomSelectSet.Add(walkingLineHnd);

                                HashSet<IFCAnyHandle> walkingLineItems = new HashSet<IFCAnyHandle>();
                                walkingLineItems.Add(IFCInstanceExporter.CreateGeometricSet(file, geomSelectSet));

                                IFCAnyHandle walkingLineRep = RepresentationUtil.CreateGeometricSetRep(exporterIFC, landing, categoryId, "Axis",
                                    contextOfItemsFootPrint, walkingLineItems);
                                reps.Add(walkingLineRep);
                            }

                            string landingGUID = ExporterIFCUtils.CreateGUID(landing);
                            string origLandingName = origStairName + " Landing " + index;
                            string landingName = NamingUtil.GetNameOverride(landing, origLandingName);
                            string landingDescription = NamingUtil.GetDescriptionOverride(landing, stairDescription);
                            string landingObjectType = NamingUtil.GetObjectTypeOverride(landing, stairObjectType);
                            IFCAnyHandle landingLocalPlacement = ecData.GetLocalPlacement();
                            string landingElementTag = NamingUtil.CreateIFCElementId(landing);

                            IFCAnyHandle representation = IFCInstanceExporter.CreateProductDefinitionShape(exporterIFC.GetFile(), null, null, reps);

                            IFCAnyHandle landingHnd = IFCInstanceExporter.CreateSlab(file, landingGUID, ownerHistory,
                                landingName, landingDescription, landingObjectType, landingLocalPlacement, representation, landingElementTag,
                                IFCSlabType.Landing);

                            componentHandles.Add(landingHnd);
                            componentExtrusionData.Add(ecData);

                            productWrapper.AddElement(landingHnd, placementSetter.GetLevelInfo(), ecData, false);
                            ExporterCacheManager.HandleToElementCache.Register(landingHnd, landing.Id);
                        }
                    }

                    // Get List of supports to export their geometry.  Supports are not exposed to API, so export as generic Element.
                    ICollection<ElementId> supportIds = stair.GetStairsSupports();
                    index = 0;
                    foreach (ElementId supportId in supportIds)
                    {
                        index++;
                        Element support = doc.GetElement(supportId);

                        using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                        {
                            ecData.SetLocalPlacement(placementSetter.GetPlacement());
                            ecData.ReuseLocalPlacement = false;

                            GeometryElement supportGeometryElement = support.get_Geometry(geomOptions);
                            BodyData bodyData;
                            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                            IFCAnyHandle representation = RepresentationUtil.CreateBRepProductDefinitionShape(app, exporterIFC,
                                support, categoryId, supportGeometryElement, bodyExporterOptions, null, ecData, out bodyData);

                            if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation))
                            {
                                ecData.ClearOpenings();
                                continue;
                            }

                            foreach (ElementId materialId in bodyData.MaterialIds)
                                materialIds.Add(materialId);

                            string supportGUID = ExporterIFCUtils.CreateGUID(support);
                            string origSupportName = origStairName + " Stringer " + index;
                            string supportName = NamingUtil.GetNameOverride(support, origSupportName);
                            string supportDescription = NamingUtil.GetDescriptionOverride(support, stairDescription);
                            string supportObjectType = NamingUtil.GetObjectTypeOverride(support, stairObjectType);
                            IFCAnyHandle supportLocalPlacement = ecData.GetLocalPlacement();
                            string supportElementTag = NamingUtil.CreateIFCElementId(support);

                            IFCAnyHandle type = GetMemberTypeHandle(exporterIFC, support);

                            IFCAnyHandle supportHnd = IFCInstanceExporter.CreateMember(file, supportGUID, ownerHistory,
                                supportName, supportDescription, supportObjectType, supportLocalPlacement, representation, supportElementTag);

                            componentHandles.Add(supportHnd);
                            componentExtrusionData.Add(ecData);

                            productWrapper.AddElement(supportHnd, placementSetter.GetLevelInfo(), ecData, false);

                            ExporterCacheManager.TypeRelationsCache.Add(type, supportHnd);
                        }
                    }

                    StairRampContainerInfo stairRampInfo = new StairRampContainerInfo(stairContainerHnd, componentHandles, null);
                    ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(stair.Id, stairRampInfo);

                    CategoryUtil.CreateMaterialAssociations(stair.Document, exporterIFC, stairContainerHnd, materialIds);

                    ExportMultistoryStair(exporterIFC, stair, numFlights, stairContainerHnd, componentHandles, componentExtrusionData,
                         materialIds, placementSetter, productWrapper);
                }
                tr.Commit();
            }
        }
Beispiel #31
0
        /// <summary>
        /// Creates openings if there is necessary.
        /// </summary>
        /// <param name="elementHandle">
        /// The element handle to create openings.
        /// </param>
        /// <param name="element">
        /// The element to create openings.
        /// </param>
        /// <param name="info">
        /// The extrusion datas.
        /// </param>
        /// <param name="extraParams">
        /// The extrusion creation data.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="originalPlacement">
        /// The original placement handle.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <param name="wrapper">
        /// The IFCProductWrapper.
        /// </param>
        private static void CreateOpeningsIfNecessaryBase(IFCAnyHandle elementHandle, Element element, IList<IFCExtrusionData> info,
           IFCExtrusionCreationData extraParams, ExporterIFC exporterIFC,
           IFCAnyHandle originalPlacement, IFCPlacementSetter setter, IFCProductWrapper wrapper)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(elementHandle))
                return;

            int sz = info.Count;
            if (sz == 0)
                return;

            IFCFile file = exporterIFC.GetFile();
            ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);
            Document document = element.Document;

            string openingObjectType = "Opening";

            int openingNumber = 1;
            for (int curr = info.Count - 1; curr >= 0; curr--)
            {
                IFCAnyHandle extrusionHandle = ExtrusionExporter.CreateExtrudedSolidFromExtrusionData(exporterIFC, element, info[curr]);
                if (IFCAnyHandleUtil.IsNullOrHasNoValue(extrusionHandle))
                    continue;

                IFCAnyHandle styledItemHnd = BodyExporter.CreateSurfaceStyleForRepItem(exporterIFC, document,
                    extrusionHandle, ElementId.InvalidElementId);
                        
                HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
                bodyItems.Add(extrusionHandle);

                IFCAnyHandle contextOfItems = exporterIFC.Get3DContextHandle("Body");
                IFCAnyHandle bodyRep = RepresentationUtil.CreateSweptSolidRep(exporterIFC, element, categoryId, contextOfItems, bodyItems, null);
                IList<IFCAnyHandle> representations = new List<IFCAnyHandle>();
                representations.Add(bodyRep);

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

                IFCAnyHandle openingPlacement = ExporterUtil.CopyLocalPlacement(file, originalPlacement);
                string guid = ExporterIFCUtils.CreateGUID();
                IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                string openingName = NamingUtil.GetNameOverride(element, NamingUtil.CreateIFCName(exporterIFC, openingNumber++));
                string elementId = NamingUtil.CreateIFCElementId(element);
                IFCAnyHandle openingElement = IFCInstanceExporter.CreateOpeningElement(file, guid, ownerHistory,
                   openingName, null, openingObjectType, openingPlacement, openingRep, elementId);
                wrapper.AddElement(openingElement, setter, extraParams, true);
                if (ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities && (extraParams != null))
                    ExporterIFCUtils.CreateOpeningQuantities(exporterIFC, openingElement, extraParams);

                string voidGuid = ExporterIFCUtils.CreateGUID();
                IFCInstanceExporter.CreateRelVoidsElement(file, voidGuid, ownerHistory, null, null, elementHandle, openingElement);
            }
        }
Beispiel #32
0
        /// <summary>
        /// Exports the top stories of a multistory ramp.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="ramp">The ramp element.</param>
        /// <param name="numFlights">The number of flights for a multistory ramp.</param>
        /// <param name="ownerHistory">The owner history.</param>
        /// <param name="localPlacement">The local placement of the IfcRamp container.</param>
        /// <param name="containedRampLocalPlacement">The local placement of the IfcRamp containing the ramp geometry.</param>
        /// <param name="representation">The ramp geometry representation.</param>
        /// <param name="rampName">The ramp name.</param>
        /// <param name="rampObjectType">The ramp object type.</param>
        /// <param name="rampDescription">The ramp description.</param>
        /// <param name="elementTag">The ramp element tag.</param>
        /// <param name="rampType">The ramp type.</param>
        /// <param name="ecData">The extrusion creation data.</param>
        /// <param name="placementSetter">The placement setter.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportMultistoryRamp(ExporterIFC exporterIFC, Element ramp, int numFlights,
                                                IFCAnyHandle ownerHistory, IFCAnyHandle localPlacement, IFCAnyHandle containedRampLocalPlacement, IFCAnyHandle representation,
                                                string rampName, string rampObjectType, string rampDescription, string elementTag, IFCRampType rampType,
                                                IFCExtrusionCreationData ecData, IFCPlacementSetter placementSetter, IFCProductWrapper productWrapper)
        {
            if (numFlights < 2)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            IFCAnyHandle   relPlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);
            IFCAnyHandle   ptHnd        = IFCAnyHandleUtil.GetLocation(relPlacement);
            IList <double> origCoords   = IFCAnyHandleUtil.GetCoordinates(ptHnd);

            double heightNonScaled = GetRampHeight(exporterIFC, ramp);
            double scale           = exporterIFC.LinearScale;

            for (int ii = 1; ii < numFlights; ii++)
            {
                double       newOffsetScaled = 0.0;
                IFCAnyHandle newLevelHnd     = null;
                IFCLevelInfo currLevelInfo   =
                    placementSetter.GetOffsetLevelInfoAndHandle(heightNonScaled * ii, scale, out newLevelHnd, out newOffsetScaled);
                if (currLevelInfo == null)
                {
                    currLevelInfo = placementSetter.GetLevelInfo();
                }

                XYZ          orig = new XYZ(0.0, 0.0, newOffsetScaled);
                IFCAnyHandle relativePlacementHnd        = ExporterUtil.CreateAxis2Placement3D(file, orig);
                IFCAnyHandle containedLocalPlacementCopy = IFCInstanceExporter.CreateLocalPlacement(file, newLevelHnd, relativePlacementHnd);

                if (ptHnd.HasValue)
                {
                    IFCAnyHandle relPlacementCopy = GeometryUtil.GetRelativePlacementFromLocalPlacement(containedLocalPlacementCopy);
                    IFCAnyHandle newPt            = IFCAnyHandleUtil.GetLocation(relPlacement);

                    IList <double> newCoords = new List <double>();
                    newCoords.Add(origCoords[0]);
                    newCoords.Add(origCoords[1]);
                    newCoords.Add(origCoords[2]);
                    if (newPt.HasValue)
                    {
                        IList <double> addToCoords = IFCAnyHandleUtil.GetCoordinates(newPt);
                        newCoords[0] += addToCoords[0];
                        newCoords[1] += addToCoords[1];
                        newCoords[2]  = addToCoords[2];
                    }

                    IFCAnyHandle locPt = IFCInstanceExporter.CreateCartesianPoint(file, newCoords);
                    IFCAnyHandleUtil.SetAttribute(relPlacementCopy, "Location", locPt);
                }

                ElementId    catId = CategoryUtil.GetSafeCategoryId(ramp);
                IFCAnyHandle representationCopy = ExporterUtil.CopyProductDefinitionShape(exporterIFC, ramp, catId, representation);

                string localRampName = rampName + ":" + (ii + 1);

                List <IFCAnyHandle> components           = new List <IFCAnyHandle>();
                IFCAnyHandle        containedRampCopyHnd = IFCInstanceExporter.CreateRamp(file, ExporterIFCUtils.CreateGUID(), ownerHistory,
                                                                                          localRampName, rampDescription, rampObjectType, containedLocalPlacementCopy, representationCopy, elementTag, rampType);
                components.Add(containedRampCopyHnd);

                productWrapper.AddElement(containedRampCopyHnd, currLevelInfo, ecData, false);

                IFCAnyHandle rampLocalPlacementCopy = ExporterUtil.CopyLocalPlacement(file, containedRampLocalPlacement);

                IFCAnyHandle rampCopyHnd = IFCInstanceExporter.CreateRamp(file, ExporterIFCUtils.CreateGUID(), ownerHistory, localRampName,
                                                                          rampDescription, rampObjectType, rampLocalPlacementCopy, null, elementTag, rampType);

                productWrapper.AddElement(rampCopyHnd, currLevelInfo, ecData, LevelUtil.AssociateElementToLevel(ramp));

                StairRampContainerInfo stairRampInfo = new StairRampContainerInfo(rampCopyHnd, components, rampLocalPlacementCopy);
                ExporterCacheManager.StairRampContainerInfoCache.AppendStairRampContainerInfo(ramp.Id, stairRampInfo);
            }
        }
Beispiel #33
0
        /// <summary>
        /// Exports an element as IFC covering.
        /// </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 IFCProductWrapper.
        /// </param>
        public static void ExportCovering(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, string ifcEnumType, IFCProductWrapper productWrapper)
        {
            bool exportParts = PartExporter.CanExportParts(element);
            if (exportParts && !PartExporter.CanExportElementInPartExport(element, element.Level.Id, false))
                return;

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

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    IFCAnyHandle prodRep = exportParts ? null : RepresentationUtil.CreateSurfaceProductDefinitionShape(exporterIFC,
                       element, geomElem, false, false);

                    string instanceGUID = ExporterIFCUtils.CreateGUID(element);
                    string origInstanceName = exporterIFC.GetName();
                    string instanceName = NamingUtil.GetNameOverride(element, origInstanceName);
                    string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                    string instanceObjectType = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                    string instanceElemId = NamingUtil.CreateIFCElementId(element);
                    Toolkit.IFCCoveringType coveringType = GetIFCCoveringType(element, ifcEnumType);

                    IFCAnyHandle covering = IFCInstanceExporter.CreateCovering(file, instanceGUID, exporterIFC.GetOwnerHistoryHandle(),
                        instanceName, instanceDescription, instanceObjectType, setter.GetPlacement(), prodRep, instanceElemId, coveringType);

                    if (exportParts)
                    {
                        PartExporter.ExportHostPart(exporterIFC, element, covering, productWrapper, setter, setter.GetPlacement(), null);
                    }
                    productWrapper.AddElement(covering, setter, null, LevelUtil.AssociateElementToLevel(element));

                    Ceiling ceiling = element as Ceiling;
                    if (ceiling != null && !exportParts)
                    {
                        HostObjectExporter.ExportHostObjectMaterials(exporterIFC, ceiling, covering,
                            geomElem, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3);
                    }

                    ExporterIFCUtils.CreateCoveringPropertySet(exporterIFC, element, productWrapper);
                    PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);
                }
                transaction.Commit();
            }
        }
        /// <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();
                    IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData();

                    ElementId catId = CategoryUtil.GetSafeCategoryId(element);


                    IFCSolidMeshGeometryInfo solidMeshInfo = ExporterIFCUtils.GetSolidMeshGeometry(exporterIFC, geometryElement, Transform.Identity);
                    IList<Solid> solids = solidMeshInfo.GetSolids();
                    IList<Mesh> polyMeshes = solidMeshInfo.GetMeshes();

                    bool tryToExportAsExtrusion = true;
                    if (solids.Count != 1 || polyMeshes.Count != 0)
                        tryToExportAsExtrusion = false;

                    IFCAnyHandle shapeRep = BodyExporter.ExportBody(element.Document.Application, exporterIFC, catId, solids, polyMeshes, tryToExportAsExtrusion, extraParams);
                    if (!shapeRep.HasValue)
                        return;

                    IList<IFCAnyHandle> shapeReps = new List<IFCAnyHandle>();
                    shapeReps.Add(shapeRep);
                    IFCAnyHandle productRepresentation = file.CreateProductDefinitionShape(IFCLabel.Create(), IFCLabel.Create(), shapeReps);

                    IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                    ElementId typeId = element.GetTypeId();
                    ElementType type = element.Document.get_Element(typeId) as ElementType;
                    IFCTypeInfo currentTypeInfo = exporterIFC.FindType(typeId, false);

                    bool found = currentTypeInfo.IsValid();
                    if (!found)
                    {
                        IFCLabel typeGUID = IFCLabel.CreateGUID(type);
                        IFCLabel origTypeName = NamingUtil.CreateIFCName(exporterIFC, -1);
                        IFCLabel typeName = NamingUtil.GetNameOverride(type, origTypeName);
                        IFCLabel typeObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, type);
                        IFCLabel applicableOccurance = NamingUtil.GetObjectTypeOverride(type, typeObjectType);
                        IFCLabel typeDescription = NamingUtil.GetDescriptionOverride(type, IFCLabel.Create());
                        IFCLabel 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 (styleHandle.HasValue)
                        {
                            currentTypeInfo.SetStyle(styleHandle);
                            exporterIFC.AddType(typeId, false, currentTypeInfo);
                        }
                    }
                    IFCLabel instanceGUID = IFCLabel.CreateGUID(element);
                    IFCLabel origInstanceName = NamingUtil.CreateIFCName(exporterIFC, -1);
                    IFCLabel instanceName = NamingUtil.GetNameOverride(element, origInstanceName);
                    IFCLabel objectType = NamingUtil.CreateIFCObjectName(exporterIFC, element);
                    IFCLabel instanceObjectType = NamingUtil.GetObjectTypeOverride(element, objectType);
                    IFCLabel instanceDescription = NamingUtil.GetDescriptionOverride(element, IFCLabel.Create());
                    IFCLabel instanceElemId = NamingUtil.CreateIFCElementId(element);

                    bool roomRelated = !FamilyExporterUtil.IsDistributionFlowElementSubType(exportType);

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

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

                    if (!instanceHandle.HasValue)
                        return;

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

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

                    if (currentTypeInfo.IsValid())
                        exporterIFC.AddTypeRelation(currentTypeInfo.GetStyle(), instanceHandle);

                    ExporterIFCUtils.CreateGenericElementPropertySet(exporterIFC, element, productWrapper);

                    tr.Commit();
                }
            }
        }
Beispiel #35
0
        /// <summary>
        /// Exports an element to IFC footing.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="ifcEnumType">
        /// The string value represents the IFC type.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportFooting(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement,
                                         string ifcEnumType, IFCProductWrapper productWrapper)
        {
            // export parts or not
            bool exportParts = PartExporter.CanExportParts(element);

            if (exportParts && !PartExporter.CanExportElementInPartExport(element, element.Level.Id, false))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(setter.GetPlacement());

                        IFCAnyHandle prodRep = null;
                        if (!exportParts)
                        {
                            ElementId catId = CategoryUtil.GetSafeCategoryId(element);

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

                        string instanceGUID                = ExporterIFCUtils.CreateGUID(element);
                        string origInstanceName            = exporterIFC.GetName();
                        string instanceName                = NamingUtil.GetNameOverride(element, origInstanceName);
                        string instanceDescription         = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceObjectType          = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                        string instanceElemId              = NamingUtil.CreateIFCElementId(element);
                        Toolkit.IFCFootingType footingType = GetIFCFootingType(element, ifcEnumType);

                        IFCAnyHandle footing = IFCInstanceExporter.CreateFooting(file, instanceGUID, exporterIFC.GetOwnerHistoryHandle(),
                                                                                 instanceName, instanceDescription, instanceObjectType, ecData.GetLocalPlacement(), prodRep, instanceElemId, footingType);

                        if (exportParts)
                        {
                            PartExporter.ExportHostPart(exporterIFC, element, footing, productWrapper, setter, setter.GetPlacement(), null);
                        }

                        productWrapper.AddElement(footing, setter, ecData, LevelUtil.AssociateElementToLevel(element));

                        OpeningUtil.CreateOpeningsIfNecessary(footing, element, ecData, exporterIFC, ecData.GetLocalPlacement(), setter, productWrapper);

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

                tr.Commit();
            }
        }
Beispiel #36
0
        /// <summary>
        /// Exports the top stories of a multistory ramp.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="ramp">The ramp element.</param>
        /// <param name="numFlights">The number of flights for a multistory ramp.</param>
        /// <param name="ownerHistory">The owner history.</param>
        /// <param name="localPlacement">The local placement of the IfcRamp container.</param>
        /// <param name="containedRampLocalPlacement">The local placement of the IfcRamp containing the ramp geometry.</param>
        /// <param name="representation">The ramp geometry representation.</param>
        /// <param name="rampName">The ramp name.</param>
        /// <param name="rampObjectType">The ramp object type.</param>
        /// <param name="rampDescription">The ramp description.</param>
        /// <param name="elementTag">The ramp element tag.</param>
        /// <param name="rampType">The ramp type.</param>
        /// <param name="ecData">The extrusion creation data.</param>
        /// <param name="placementSetter">The placement setter.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportMultistoryRamp(ExporterIFC exporterIFC, Element ramp, int numFlights,
            IFCAnyHandle ownerHistory, IFCAnyHandle localPlacement, IFCAnyHandle containedRampLocalPlacement, IFCAnyHandle representation,
            string rampName, string rampObjectType, string rampDescription, string elementTag, IFCRampType rampType,
            IFCExtrusionCreationData ecData, IFCPlacementSetter placementSetter, IFCProductWrapper productWrapper)
        {
            if (numFlights < 2)
                return;

            IFCFile file = exporterIFC.GetFile();

            IFCAnyHandle relPlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);
            IFCAnyHandle ptHnd = IFCAnyHandleUtil.GetLocation(relPlacement);
            IList<double> origCoords = IFCAnyHandleUtil.GetCoordinates(ptHnd);

            double heightNonScaled = GetRampHeight(exporterIFC, ramp);
            double scale = exporterIFC.LinearScale;

            for (int ii = 1; ii < numFlights; ii++)
            {
                double newOffsetScaled = 0.0;
                IFCAnyHandle newLevelHnd = null;
                IFCLevelInfo currLevelInfo =
                    placementSetter.GetOffsetLevelInfoAndHandle(heightNonScaled * ii, scale, out newLevelHnd, out newOffsetScaled);
                if (currLevelInfo == null)
                    currLevelInfo = placementSetter.GetLevelInfo();

                XYZ orig = new XYZ(0.0, 0.0, newOffsetScaled);
                IFCAnyHandle relativePlacementHnd = ExporterUtil.CreateAxis2Placement3D(file, orig);
                IFCAnyHandle containedLocalPlacementCopy = IFCInstanceExporter.CreateLocalPlacement(file, newLevelHnd, relativePlacementHnd);

                if (ptHnd.HasValue)
                {
                    IFCAnyHandle relPlacementCopy = GeometryUtil.GetRelativePlacementFromLocalPlacement(containedLocalPlacementCopy);
                    IFCAnyHandle newPt = IFCAnyHandleUtil.GetLocation(relPlacement);

                    IList<double> newCoords = new List<double>();
                    newCoords.Add(origCoords[0]);
                    newCoords.Add(origCoords[1]);
                    newCoords.Add(origCoords[2]);
                    if (newPt.HasValue)
                    {
                        IList<double> addToCoords = IFCAnyHandleUtil.GetCoordinates(newPt);
                        newCoords[0] += addToCoords[0];
                        newCoords[1] += addToCoords[1];
                        newCoords[2] = addToCoords[2];
                    }

                    IFCAnyHandle locPt = IFCInstanceExporter.CreateCartesianPoint(file, newCoords);
                    IFCAnyHandleUtil.SetAttribute(relPlacementCopy, "Location", locPt);
                }

                ElementId catId = CategoryUtil.GetSafeCategoryId(ramp);
                IFCAnyHandle representationCopy = ExporterUtil.CopyProductDefinitionShape(exporterIFC, ramp, catId, representation);

                string localRampName = rampName + ":" + (ii + 1);

                List<IFCAnyHandle> components = new List<IFCAnyHandle>();
                IFCAnyHandle containedRampCopyHnd = IFCInstanceExporter.CreateRamp(file, ExporterIFCUtils.CreateGUID(), ownerHistory,
                    localRampName, rampDescription, rampObjectType, containedLocalPlacementCopy, representationCopy, elementTag, rampType);
                components.Add(containedRampCopyHnd);

                productWrapper.AddElement(containedRampCopyHnd, currLevelInfo, ecData, false);

                IFCAnyHandle rampLocalPlacementCopy = ExporterUtil.CopyLocalPlacement(file, containedRampLocalPlacement);

                IFCAnyHandle rampCopyHnd = IFCInstanceExporter.CreateRamp(file, ExporterIFCUtils.CreateGUID(), ownerHistory, localRampName,
                    rampDescription, rampObjectType, rampLocalPlacementCopy, null, elementTag, rampType);

                productWrapper.AddElement(rampCopyHnd, currLevelInfo, ecData, LevelUtil.AssociateElementToLevel(ramp));

                StairRampContainerInfo stairRampInfo = new StairRampContainerInfo(rampCopyHnd, components, rampLocalPlacementCopy);
                ExporterCacheManager.StairRampContainerInfoCache.AppendStairRampContainerInfo(ramp.Id, stairRampInfo);
            }
        }
        /// <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 IFCProductWrapper.</param>
        /// <param name="setter">The IFCPlacementSetter.</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="instanceElemId">The element id label.</param>
        /// <returns>The handle.</returns>
        public static IFCAnyHandle ExportGenericInstance(IFCExportType type,
           ExporterIFC exporterIFC, Element familyInstance,
           IFCProductWrapper wrapper, IFCPlacementSetter setter, IFCExtrusionCreationData extraParams,
           IFCLabel instanceGUID, IFCAnyHandle ownerHistory,
           IFCLabel instanceName, IFCLabel instanceDescription, IFCLabel instanceObjectType,
           IFCAnyHandle productRepresentation,
           IFCLabel instanceElemId)
        {
            IFCFile file = exporterIFC.GetFile();
            Document doc = familyInstance.Document;

            bool isRoomRelated = IsRoomRelated(type);

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

            IFCAnyHandle instanceHandle = IFCAnyHandle.Create();
            switch (type)
            {
                case IFCExportType.ExportColumnType:
                    {
                        instanceHandle = file.CreateColumn(instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        break;
                    }
                case IFCExportType.ExportMemberType:
                    {
                        instanceHandle = file.CreateMember(instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        break;
                    }
                case IFCExportType.ExportPlateType:
                    {
                        instanceHandle = file.CreatePlate(instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        break;
                    }
                default:
                    {
                        if (IsFurnishingElementSubType(type))
                        {
                            instanceHandle = file.CreateFurnishingElement(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (IsDistributionFlowElementSubType(type))
                        {
                            instanceHandle = file.CreateDistributionFlowElement(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (IsEnergyConversionDeviceSubType(type))
                        {
                            instanceHandle = file.CreateEnergyConversionDevice(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (IsFlowFittingSubType(type))
                        {
                            instanceHandle = file.CreateFlowFitting(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (IsFlowMovingDeviceSubType(type))
                        {
                            instanceHandle = file.CreateFlowMovingDevice(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (IsFlowSegmentSubType(type))
                        {
                            instanceHandle = file.CreateFlowSegment(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (IsFlowStorageDeviceSubType(type))
                        {
                            instanceHandle = file.CreateFlowStorageDevice(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (IsFlowTerminalSubType(type))
                        {
                            instanceHandle = file.CreateFlowTerminal(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (IsFlowTreatmentDeviceSubType(type))
                        {
                            instanceHandle = file.CreateFlowTreatmentDevice(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        else if (IsFlowControllerSubType(type))
                        {
                            instanceHandle = file.CreateFlowController(instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceElemId);
                        }
                        break;
                    }
            }

            if (instanceHandle.HasValue)
            {
                if (roomId == ElementId.InvalidElementId)
                {
                    wrapper.AddElement(instanceHandle, setter, extraParams, true);
                }
                else
                {
                    exporterIFC.RelateSpatialElement(roomId, instanceHandle);
                    wrapper.AddElement(instanceHandle, setter, extraParams, false);
                }
            }
            return instanceHandle;
        }
Beispiel #38
0
        /// <summary>
        /// Exports a roof to IfcRoof.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="ifcEnumType">The roof type.</param>
        /// <param name="roof">The roof element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportRoof(ExporterIFC exporterIFC, string ifcEnumType, Element roof, GeometryElement geometryElement,
                                      IFCProductWrapper productWrapper)
        {
            if (roof == null || geometryElement == null)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, roof))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.PossibleExtrusionAxes   = IFCExtrusionAxes.TryZ;
                        ecData.AreInnerRegionsOpenings = true;
                        ecData.SetLocalPlacement(placementSetter.GetPlacement());

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(roof);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                        IFCAnyHandle        representation      = RepresentationUtil.CreateBRepProductDefinitionShape(roof.Document.Application, exporterIFC, roof,
                                                                                                                      categoryId, geometryElement, bodyExporterOptions, null, ecData);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation))
                        {
                            ecData.ClearOpenings();
                            return;
                        }

                        bool exportSlab = ecData.ScaledLength > MathUtil.Eps();

                        string       guid            = ExporterIFCUtils.CreateGUID(roof);
                        IFCAnyHandle ownerHistory    = exporterIFC.GetOwnerHistoryHandle();
                        string       origRoofName    = exporterIFC.GetName();
                        string       roofName        = NamingUtil.GetNameOverride(roof, origRoofName);
                        string       roofDescription = NamingUtil.GetDescriptionOverride(roof, null);
                        string       roofObjectType  = NamingUtil.GetObjectTypeOverride(roof, NamingUtil.CreateIFCObjectName(exporterIFC, roof));
                        IFCAnyHandle localPlacement  = ecData.GetLocalPlacement();
                        string       elementTag      = NamingUtil.CreateIFCElementId(roof);
                        IFCRoofType  roofType        = GetIFCRoofType(ifcEnumType);

                        IFCAnyHandle roofHnd = IFCInstanceExporter.CreateRoof(file, guid, ownerHistory, roofName, roofDescription,
                                                                              roofObjectType, localPlacement, exportSlab ? null : representation, elementTag, roofType);

                        productWrapper.AddElement(roofHnd, placementSetter.GetLevelInfo(), ecData, LevelUtil.AssociateElementToLevel(roof));

                        if (exportSlab)
                        {
                            string       slabGUID = ExporterIFCUtils.CreateSubElementGUID(roof, (int)IFCRoofSubElements.RoofSlabStart);
                            string       slabName = roofName + ":1";
                            IFCAnyHandle slabLocalPlacementHnd = ExporterUtil.CopyLocalPlacement(file, localPlacement);

                            IFCAnyHandle slabHnd = IFCInstanceExporter.CreateSlab(file, slabGUID, ownerHistory, slabName,
                                                                                  roofDescription, roofObjectType, slabLocalPlacementHnd, representation, elementTag, IFCSlabType.Roof);
                            OpeningUtil.CreateOpeningsIfNecessary(slabHnd, roof, ecData, exporterIFC, slabLocalPlacementHnd,
                                                                  placementSetter, productWrapper);

                            ExporterUtil.RelateObject(exporterIFC, roofHnd, slabHnd);

                            productWrapper.AddElement(slabHnd, placementSetter.GetLevelInfo(), ecData, false);
                        }
                    }
                    tr.Commit();
                }
            }
        }
Beispiel #39
0
        /// <summary>
        /// Exports a staircase to IfcStair, without decomposing into separate runs and landings.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="ifcEnumType">The stairs type.</param>
        /// <param name="stair">The stairs element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="numFlights">The number of flights for a multistory staircase.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportStairAsSingleGeometry(ExporterIFC exporterIFC, string ifcEnumType, Element stair, GeometryElement geometryElement,
            int numFlights, IFCProductWrapper productWrapper)
        {
            if (stair == null || geometryElement == null)
                return;

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, stair))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(placementSetter.GetPlacement());
                        ecData.ReuseLocalPlacement = false;

                        GeometryElement stairsGeom = GeometryUtil.GetOneLevelGeometryElement(geometryElement);

                        BodyData bodyData;
                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(stair);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions();
                        IFCAnyHandle representation = RepresentationUtil.CreateBRepProductDefinitionShape(stair.Document.Application, exporterIFC,
                            stair, categoryId, stairsGeom, bodyExporterOptions, null, ecData, out bodyData);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation))
                        {
                            ecData.ClearOpenings();
                            return;
                        }

                        string containedStairGuid = ExporterIFCUtils.CreateSubElementGUID(stair, (int)IFCStairSubElements.ContainedStair);
                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                        string origStairName = exporterIFC.GetName();
                        string stairName = NamingUtil.GetNameOverride(stair, origStairName);
                        string stairDescription = NamingUtil.GetDescriptionOverride(stair, null);
                        string stairObjectType = NamingUtil.GetObjectTypeOverride(stair, NamingUtil.CreateIFCObjectName(exporterIFC, stair));
                        IFCAnyHandle containedStairLocalPlacement = ecData.GetLocalPlacement();
                        string elementTag = NamingUtil.CreateIFCElementId(stair);
                        IFCStairType stairType = GetIFCStairType(ifcEnumType);

                        List<IFCAnyHandle> components = new List<IFCAnyHandle>();
                        IList<IFCExtrusionCreationData> componentExtrusionData = new List<IFCExtrusionCreationData>();
                        IFCAnyHandle containedStairHnd = IFCInstanceExporter.CreateStair(file, containedStairGuid, ownerHistory, stairName,
                            stairDescription, stairObjectType, containedStairLocalPlacement, representation, elementTag, stairType);
                        components.Add(containedStairHnd);
                        componentExtrusionData.Add(ecData);
                        //productWrapper.AddElement(containedStairHnd, placementSetter.GetLevelInfo(), ecData, false);

                        string guid = ExporterIFCUtils.CreateGUID(stair);
                        IFCAnyHandle localPlacement = ecData.GetLocalPlacement();

                        IFCAnyHandle stairHnd = IFCInstanceExporter.CreateStair(file, guid, ownerHistory, stairName,
                            stairDescription, stairObjectType, localPlacement, null, elementTag, stairType);

                        productWrapper.AddElement(stairHnd, placementSetter.GetLevelInfo(), ecData, LevelUtil.AssociateElementToLevel(stair));

                        IFCAnyHandle emptyPlacement = null;
                        StairRampContainerInfo stairRampInfo = new StairRampContainerInfo(stairHnd, components, emptyPlacement);
                        ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(stair.Id, stairRampInfo);

                        ExportMultistoryStair(exporterIFC, stair, numFlights, stairHnd, components, componentExtrusionData,
                            bodyData.MaterialIds, placementSetter, productWrapper);
                    }
                    tr.Commit();
                }
            }
        }
        /// <summary>
        /// Export Curtain Walls and Roofs.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="element">
        /// The element to be exported.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportBase(ExporterIFC exporterIFC, ICollection <ElementId> allSubElements,
                                      Element element, IFCProductWrapper wrapper)
        {
            IFCFile      file         = exporterIFC.GetFile();
            IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

            IFCPlacementSetter setter = null;

            using (IFCProductWrapper curtainWallSubWrapper = IFCProductWrapper.Create(wrapper, false))
            {
                try
                {
                    IFCAnyHandle localPlacement = null;
                    bool         canExportCurtainWallAsContainer = CanExportCurtainWallAsContainer(allSubElements, element.Document);
                    IFCAnyHandle rep = null;
                    if (!canExportCurtainWallAsContainer)
                    {
                        setter         = IFCPlacementSetter.Create(exporterIFC, element);
                        localPlacement = setter.GetPlacement();
                        rep            = ExportCurtainObjectCommonAsOneBRep(allSubElements, element, exporterIFC, setter, localPlacement);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(rep))
                        {
                            return;
                        }
                    }
                    else
                    {
                        ExportCurtainObjectCommonAsContainer(allSubElements, element, exporterIFC, curtainWallSubWrapper);
                        // This has to go LAST.  Why?  Because otherwise we apply the level transform twice -- once in the familyTrf, once here.
                        // This will be used just to put the CurtainWall on the right level.
                        setter         = IFCPlacementSetter.Create(exporterIFC, element);
                        localPlacement = setter.GetPlacement();
                    }

                    string objectType = NamingUtil.CreateIFCObjectName(exporterIFC, element);

                    {
                        IFCAnyHandle prodRepHnd = null;
                        IFCAnyHandle elemHnd    = null;
                        string       elemGUID   = ExporterIFCUtils.CreateGUID(element);
                        string       elemName   = NamingUtil.GetNameOverride(element, exporterIFC.GetName());
                        string       elemDesc   = NamingUtil.GetDescriptionOverride(element, null);
                        string       elemType   = NamingUtil.GetObjectTypeOverride(element, objectType);
                        string       elemId     = NamingUtil.CreateIFCElementId(element);
                        if (element is Wall || element is CurtainSystem || IsLegacyCurtainElement(element))
                        {
                            elemHnd = IFCInstanceExporter.CreateCurtainWall(file, elemGUID, ownerHistory, elemName, elemDesc, elemType, localPlacement, prodRepHnd, elemId);
                        }
                        else if (element is RoofBase)
                        {
                            //need to convert the string to enum
                            string ifcEnumType = CategoryUtil.GetIFCEnumTypeName(exporterIFC, element);
                            elemHnd = IFCInstanceExporter.CreateRoof(file, elemGUID, ownerHistory, elemName, elemDesc, elemType, localPlacement,
                                                                     prodRepHnd, elemId, RoofExporter.GetIFCRoofType(ifcEnumType));
                        }
                        else
                        {
                            return;
                        }

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

                        wrapper.AddElement(elemHnd, setter, null, true);

                        ExporterIFCUtils.CreateCurtainWallPropertySet(exporterIFC, element, wrapper);
                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, wrapper);
                        ICollection <IFCAnyHandle> relatedElementIds = curtainWallSubWrapper.GetAllObjects();
                        if (relatedElementIds.Count > 0)
                        {
                            string guid = ExporterIFCUtils.CreateSubElementGUID(element, (int)IFCCurtainWallSubElements.RelAggregates);
                            HashSet <IFCAnyHandle> relatedElementIdSet = new HashSet <IFCAnyHandle>(relatedElementIds);
                            IFCInstanceExporter.CreateRelAggregates(file, guid, ownerHistory, null, null, elemHnd, relatedElementIdSet);
                        }
                        exporterIFC.RegisterSpaceBoundingElementHandle(elemHnd, element.Id, ElementId.InvalidElementId);
                    }
                }
                finally
                {
                    if (setter != null)
                    {
                        setter.Dispose();
                    }
                }
            }
        }
Beispiel #41
0
        /// <summary>
        /// Exports a legacy staircase or ramp to IfcStair or IfcRamp, composing into separate runs and landings.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="ifcEnumType">>The ifc type.</param>
        /// <param name="legacyStair">The legacy stairs or ramp element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="useCoarseTessellation">Export using a coarse tessellation if true.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportLegacyStairOrRampAsContainer(ExporterIFC exporterIFC, string ifcEnumType, Element legacyStair, GeometryElement geometryElement,
            bool useCoarseTessellation, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();
            Autodesk.Revit.ApplicationServices.Application app = legacyStair.Document.Application;
            ElementId categoryId = CategoryUtil.GetSafeCategoryId(legacyStair);

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, legacyStair))
                {
                    IFCLegacyStairOrRamp legacyStairOrRamp = ExporterIFCUtils.GetLegacyStairOrRampComponents(exporterIFC, legacyStair);
                    if (legacyStairOrRamp == null)
                        return;

                    bool isRamp = legacyStairOrRamp.IsRamp;

                    using (IFCExtrusionCreationData ifcECData = new IFCExtrusionCreationData())
                    {
                        ifcECData.SetLocalPlacement(placementSetter.GetPlacement());

                        string stairDescription = NamingUtil.GetDescriptionOverride(legacyStair, null);
                        string stairObjectType = NamingUtil.GetObjectTypeOverride(legacyStair, NamingUtil.CreateIFCObjectName(exporterIFC, legacyStair));
                        string stairElementTag = NamingUtil.CreateIFCElementId(legacyStair);

                        double defaultHeight = GetDefaultHeightForLegacyStair(exporterIFC.LinearScale);
                        double stairHeight = GetStairsHeightForLegacyStair(exporterIFC, legacyStair, defaultHeight);
                        int numFlights = GetNumFlightsForLegacyStair(exporterIFC, legacyStair, defaultHeight);

                        List<IFCLevelInfo> localLevelInfoForFlights = new List<IFCLevelInfo>();
                        List<IFCAnyHandle> localPlacementForFlights = new List<IFCAnyHandle>();
                        List<List<IFCAnyHandle>> components = new List<List<IFCAnyHandle>>();

                        components.Add(new List<IFCAnyHandle>());
                        if (numFlights > 1)
                        {
                            XYZ zDir = new XYZ(0.0, 0.0, 1.0);
                            XYZ xDir = new XYZ(1.0, 0.0, 0.0);
                            for (int ii = 1; ii < numFlights; ii++)
                            {
                                components.Add(new List<IFCAnyHandle>());
                                double newOffsetScaled = 0.0;
                                IFCAnyHandle newLevelHnd = null;
                                localLevelInfoForFlights.Add(
                                    placementSetter.GetOffsetLevelInfoAndHandle(stairHeight * ii, exporterIFC.LinearScale, out newLevelHnd, out newOffsetScaled));

                                XYZ orig = new XYZ(0.0, 0.0, newOffsetScaled);
                                IFCAnyHandle relativePlacement = ExporterUtil.CreateAxis2Placement3D(file, orig, zDir, xDir);
                                localPlacementForFlights.Add(IFCInstanceExporter.CreateLocalPlacement(file, newLevelHnd, relativePlacement));
                            }
                        }

                        IList<IFCAnyHandle> walkingLineReps = legacyStairOrRamp.GetWalkingLineRepresentations();
                        IList<IFCAnyHandle> boundaryReps = legacyStairOrRamp.GetBoundaryRepresentations();
                        IList<IList<GeometryObject>> geometriesOfRuns = legacyStairOrRamp.GetRunGeometries();
                        IList<int> numRisers = legacyStairOrRamp.GetNumberOfRisers();
                        IList<int> numTreads = legacyStairOrRamp.GetNumberOfTreads();
                        IList<double> treadsLength = legacyStairOrRamp.GetTreadsLength();
                        double riserHeight = legacyStairOrRamp.RiserHeight;

                        int runCount = geometriesOfRuns.Count;
                        for (int ii = 0; ii < runCount; ii++)
                        {
                            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                            if (useCoarseTessellation)
                                bodyExporterOptions.TessellationLevel = BodyExporterOptions.BodyTessellationLevel.Coarse;

                            IList<GeometryObject> geometriesOfARun = geometriesOfRuns[ii];
                            BodyData bodyData = BodyExporter.ExportBody(app, exporterIFC, legacyStair, categoryId, geometriesOfARun,
                                bodyExporterOptions, null);

                            IFCAnyHandle bodyRep = bodyData.RepresentationHnd;
                            if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep))
                            {
                                continue;
                            }


                            HashSet<IFCAnyHandle> flightHnds = new HashSet<IFCAnyHandle>();
                            List<IFCAnyHandle> representations = new List<IFCAnyHandle>();
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(walkingLineReps[ii]))
                            {
                                representations.Add(walkingLineReps[ii]);
                            }
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(boundaryReps[ii]))
                            {
                                representations.Add(boundaryReps[ii]);
                            }
                            representations.Add(bodyRep);

                            IFCAnyHandle flightRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);
                            IFCAnyHandle flightLocalPlacement = ExporterUtil.CopyLocalPlacement(file, placementSetter.GetPlacement());

                            IFCAnyHandle flightHnd;
                            string stairName = NamingUtil.GetNameOverride(legacyStair, NamingUtil.CreateIFCName(exporterIFC, ii + 1));
                            if (isRamp)
                            {
                                flightHnd = IFCInstanceExporter.CreateRampFlight(file, ExporterIFCUtils.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                    stairName, stairDescription, stairObjectType, flightLocalPlacement, flightRep, stairElementTag);
                                flightHnds.Add(flightHnd);
                                productWrapper.AddElement(flightHnd, placementSetter.GetLevelInfo(), null, false);
                            }
                            else
                            {
                                flightHnd = IFCInstanceExporter.CreateStairFlight(file, ExporterIFCUtils.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                    stairName, stairDescription, stairObjectType, flightLocalPlacement, flightRep, stairElementTag, numRisers[ii], numTreads[ii],
                                    riserHeight, treadsLength[ii]);
                                flightHnds.Add(flightHnd);
                                productWrapper.AddElement(flightHnd, placementSetter.GetLevelInfo(), null, false);
                            }

                            components[0].Add(flightHnd);
                            for (int compIdx = 1; compIdx < numFlights; compIdx++)
                            {
                                if (isRamp)
                                {
                                    IFCAnyHandle newLocalPlacement = ExporterUtil.CopyLocalPlacement(file, localPlacementForFlights[compIdx - 1]);
                                    IFCAnyHandle newProdRep = ExporterUtil.CopyProductDefinitionShape(exporterIFC, legacyStair, categoryId, IFCAnyHandleUtil.GetRepresentation(flightHnd));
                                    flightHnd = IFCInstanceExporter.CreateRampFlight(file, ExporterIFCUtils.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                        stairName, stairDescription, stairObjectType, newLocalPlacement, newProdRep, stairElementTag);
                                    components[compIdx].Add(flightHnd);
                                }
                                else
                                {
                                    IFCAnyHandle newLocalPlacement = ExporterUtil.CopyLocalPlacement(file, localPlacementForFlights[compIdx - 1]);
                                    IFCAnyHandle newProdRep = ExporterUtil.CopyProductDefinitionShape(exporterIFC, legacyStair, categoryId, IFCAnyHandleUtil.GetRepresentation(flightHnd));

                                    flightHnd = IFCInstanceExporter.CreateStairFlight(file, ExporterIFCUtils.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                        stairName, stairDescription, stairObjectType, newLocalPlacement, newProdRep, stairElementTag,
                                        numRisers[ii], numTreads[ii], riserHeight, treadsLength[ii]);
                                    components[compIdx].Add(flightHnd);
                                }
                                productWrapper.AddElement(flightHnd, placementSetter.GetLevelInfo(), null, false);
                                flightHnds.Add(flightHnd);
                            }
                        }

                        IList<IList<GeometryObject>> geometriesOfLandings = legacyStairOrRamp.GetLandingGeometries();
                        for (int ii = 0; ii < geometriesOfLandings.Count; ii++)
                        {
                            using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                            {
                                BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                                bodyExporterOptions.TessellationLevel = BodyExporterOptions.BodyTessellationLevel.Coarse;
                                IList<GeometryObject> geometriesOfALanding = geometriesOfLandings[ii];
                                BodyData bodyData = BodyExporter.ExportBody(app, exporterIFC, legacyStair, categoryId, geometriesOfALanding,
                                    bodyExporterOptions, ecData);

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

                                List<IFCAnyHandle> representations = new List<IFCAnyHandle>();
                                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(walkingLineReps[ii + runCount]))
                                {
                                    representations.Add(walkingLineReps[ii + runCount]);
                                }
                                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(boundaryReps[ii + runCount]))
                                {
                                    representations.Add(boundaryReps[ii + runCount]);
                                }
                                representations.Add(bodyRep);

                                IFCAnyHandle shapeHnd = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);
                                IFCAnyHandle landingLocalPlacement = ExporterUtil.CopyLocalPlacement(file, placementSetter.GetPlacement());
                                string stairName = NamingUtil.GetNameOverride(legacyStair, NamingUtil.CreateIFCName(exporterIFC, ii + 1));

                                IFCAnyHandle slabHnd = IFCInstanceExporter.CreateSlab(file, ExporterIFCUtils.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                    stairName, stairDescription, stairObjectType, landingLocalPlacement, shapeHnd, stairElementTag, IFCSlabType.Landing);
                                productWrapper.AddElement(slabHnd, placementSetter.GetLevelInfo(), ecData, false);

                                components[0].Add(slabHnd);
                                for (int compIdx = 1; compIdx < numFlights; compIdx++)
                                {
                                    IFCAnyHandle newLocalPlacement = ExporterUtil.CopyLocalPlacement(file, localPlacementForFlights[compIdx - 1]);
                                    IFCAnyHandle newProdRep = ExporterUtil.CopyProductDefinitionShape(exporterIFC, legacyStair, categoryId, IFCAnyHandleUtil.GetRepresentation(slabHnd));

                                    IFCAnyHandle newSlabHnd = IFCInstanceExporter.CreateSlab(file, ExporterIFCUtils.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                        stairName, stairDescription, stairObjectType, newLocalPlacement, newProdRep, stairElementTag, IFCSlabType.Landing);
                                    components[compIdx].Add(newSlabHnd);
                                    productWrapper.AddElement(newSlabHnd, placementSetter.GetLevelInfo(), ecData, false);
                                }
                            }
                        }

                        IList<GeometryObject> geometriesOfStringer = legacyStairOrRamp.GetStringerGeometries();
                        for (int ii = 0; ii < geometriesOfStringer.Count; ii++)
                        {
                            using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                            {
                                BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                                bodyExporterOptions.TessellationLevel = BodyExporterOptions.BodyTessellationLevel.Coarse;
                                GeometryObject geometryOfStringer = geometriesOfStringer[ii];
                                BodyData bodyData = BodyExporter.ExportBody(app, exporterIFC, legacyStair, categoryId, geometryOfStringer,
                                    bodyExporterOptions, ecData);

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

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

                                IFCAnyHandle stringerRepHnd = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);
                                IFCAnyHandle stringerLocalPlacement = ExporterUtil.CopyLocalPlacement(file, placementSetter.GetPlacement());
                                string stairName = NamingUtil.GetNameOverride(legacyStair, NamingUtil.CreateIFCName(exporterIFC, ii + 1));

                                IFCAnyHandle memberHnd = IFCInstanceExporter.CreateMember(file, ExporterIFCUtils.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                    stairName, stairDescription, stairObjectType, stringerLocalPlacement, stringerRepHnd, stairElementTag);
                                productWrapper.AddElement(memberHnd, placementSetter.GetLevelInfo(), ecData, false);
                                PropertyUtil.CreateBeamColumnMemberBaseQuantities(exporterIFC, memberHnd, null, ecData);

                                components[0].Add(memberHnd);
                                for (int compIdx = 1; compIdx < numFlights; compIdx++)
                                {
                                    IFCAnyHandle newLocalPlacement = ExporterUtil.CopyLocalPlacement(file, localPlacementForFlights[compIdx - 1]);
                                    IFCAnyHandle newProdRep = ExporterUtil.CopyProductDefinitionShape(exporterIFC, legacyStair, categoryId, IFCAnyHandleUtil.GetRepresentation(memberHnd));

                                    IFCAnyHandle newMemberHnd = IFCInstanceExporter.CreateMember(file, ExporterIFCUtils.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                        stairName, stairDescription, stairObjectType, newLocalPlacement, newProdRep, stairElementTag);
                                    components[compIdx].Add(newMemberHnd);
                                    productWrapper.AddElement(newMemberHnd, placementSetter.GetLevelInfo(), ecData, false);
                                }
                            }
                        }

                        List<IFCAnyHandle> createdStairs = new List<IFCAnyHandle>();
                        if (isRamp)
                        {
                            IFCRampType rampType = RampExporter.GetIFCRampType(ifcEnumType);
                            string stairName = NamingUtil.GetNameOverride(legacyStair, NamingUtil.CreateIFCName(exporterIFC, 0));
                            IFCAnyHandle containedRampHnd = IFCInstanceExporter.CreateRamp(file, ExporterIFCUtils.CreateGUID(legacyStair), exporterIFC.GetOwnerHistoryHandle(),
                                stairName, stairDescription, stairObjectType, placementSetter.GetPlacement(), null, stairElementTag, rampType);
                            productWrapper.AddElement(containedRampHnd, placementSetter.GetLevelInfo(), ifcECData, true);
                            createdStairs.Add(containedRampHnd);
                        }
                        else
                        {
                            IFCStairType stairType = GetIFCStairType(ifcEnumType);
                            string stairName = NamingUtil.GetNameOverride(legacyStair, NamingUtil.CreateIFCName(exporterIFC, 0));
                            IFCAnyHandle containedStairHnd = IFCInstanceExporter.CreateStair(file, ExporterIFCUtils.CreateGUID(legacyStair), exporterIFC.GetOwnerHistoryHandle(),
                                stairName, stairDescription, stairObjectType, placementSetter.GetPlacement(), null, stairElementTag, stairType);
                            productWrapper.AddElement(containedStairHnd, placementSetter.GetLevelInfo(), ifcECData, true);
                            createdStairs.Add(containedStairHnd);
                        }

                        // multi-story stairs.
                        if (numFlights > 1)
                        {
                            IFCAnyHandle localPlacement = placementSetter.GetPlacement();
                            IFCAnyHandle relPlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);
                            IFCAnyHandle ptHnd = IFCAnyHandleUtil.GetLocation(relPlacement);
                            IList<double> origCoords = null;
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(ptHnd))
                                origCoords = IFCAnyHandleUtil.GetCoordinates(ptHnd);

                            for (int ii = 1; ii < numFlights; ii++)
                            {
                                IFCLevelInfo levelInfo = localLevelInfoForFlights[ii - 1];
                                if (levelInfo == null)
                                    levelInfo = placementSetter.GetLevelInfo();

                                localPlacement = localPlacementForFlights[ii - 1];

                                // relate to bottom stair or closest level?  For code checking, we need closest level, and
                                // that seems good enough for the general case.
                                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(ptHnd))
                                {
                                    IFCAnyHandle relPlacement2 = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);
                                    IFCAnyHandle newPt = IFCAnyHandleUtil.GetLocation(relPlacement2);

                                    List<double> newCoords = new List<double>();
                                    newCoords.Add(origCoords[0]);
                                    newCoords.Add(origCoords[1]);
                                    newCoords.Add(origCoords[2]);
                                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(newPt))
                                    {
                                        IList<double> addToCoords;
                                        addToCoords = IFCAnyHandleUtil.GetCoordinates(newPt);
                                        newCoords[0] += addToCoords[0];
                                        newCoords[1] += addToCoords[1];
                                        newCoords[2] = addToCoords[2];
                                    }

                                    IFCAnyHandle locPt = ExporterUtil.CreateCartesianPoint(file, newCoords);
                                    IFCAnyHandleUtil.SetAttribute(relPlacement2, "Location", locPt);
                                }

                                if (isRamp)
                                {
                                    IFCRampType rampType = RampExporter.GetIFCRampType(ifcEnumType);
                                    string stairName = NamingUtil.GetNameOverride(legacyStair, NamingUtil.CreateIFCName(exporterIFC, 0));
                                    IFCAnyHandle containedRampHnd = IFCInstanceExporter.CreateRamp(file, ExporterIFCUtils.CreateGUID(legacyStair), exporterIFC.GetOwnerHistoryHandle(),
                                        stairName, stairDescription, stairObjectType, localPlacement, null, stairElementTag, rampType);
                                    productWrapper.AddElement(containedRampHnd, levelInfo, ifcECData, true);
                                    //createdStairs.Add(containedRampHnd) ???????????????????????
                                }
                                else
                                {
                                    IFCStairType stairType = GetIFCStairType(ifcEnumType);
                                    string stairName = NamingUtil.GetNameOverride(legacyStair, NamingUtil.CreateIFCName(exporterIFC, 0));
                                    IFCAnyHandle containedStairHnd = IFCInstanceExporter.CreateStair(file, ExporterIFCUtils.CreateGUID(legacyStair), exporterIFC.GetOwnerHistoryHandle(),
                                        stairName, stairDescription, stairObjectType, localPlacement, null, stairElementTag, stairType);
                                    productWrapper.AddElement(containedStairHnd, levelInfo, ifcECData, true);
                                    createdStairs.Add(containedStairHnd);
                                }
                            }
                        }

                        localPlacementForFlights.Insert(0, null);

                        StairRampContainerInfo stairRampInfo = new StairRampContainerInfo(createdStairs, components, localPlacementForFlights);
                        ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(legacyStair.Id, stairRampInfo);
                    }
                }

                tr.Commit();
            }
        }
        /// <summary>
        /// Creates openings if there is necessary.
        /// </summary>
        /// <param name="elementHandle">
        /// The element handle to create openings.
        /// </param>
        /// <param name="element">
        /// The element to create openings.
        /// </param>
        /// <param name="info">
        /// The extrusion datas.
        /// </param>
        /// <param name="extraParams">
        /// The extrusion creation data.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="originalPlacement">
        /// The original placement handle.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <param name="wrapper">
        /// The IFCProductWrapper.
        /// </param>
        private static void CreateOpeningsIfNecessaryBase(IFCAnyHandle elementHandle, Element element, IList<IFCExtrusionData> info,
           IFCExtrusionCreationData extraParams, ExporterIFC exporterIFC,
           IFCAnyHandle originalPlacement, IFCPlacementSetter setter, IFCProductWrapper wrapper)
        {
            if (!elementHandle.HasValue)
                return;

            IFCFile file = exporterIFC.GetFile();
            ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

            int sz = info.Count;
            if (sz == 0)
                return;

            IFCLabel openingObjectType = IFCLabel.Create("Opening");

            int openingNumber = 1;
            for (int curr = info.Count - 1; curr >= 0; curr--)
            {
                IFCAnyHandle extrusionHandle = BodyExporter.CreateExtrudedSolidFromExtrusionData(exporterIFC, categoryId, info[curr]);
                if (!extrusionHandle.HasValue)
                    continue;

                HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
                bodyItems.Add(extrusionHandle);

                IFCAnyHandle contextOfItems = exporterIFC.Get3DContextHandle();
                IFCAnyHandle bodyRep = RepresentationUtil.CreateSweptSolidRep(exporterIFC, categoryId, contextOfItems, bodyItems,
                   IFCAnyHandle.Create());
                IList<IFCAnyHandle> representations = new List<IFCAnyHandle>();
                representations.Add(bodyRep);

                IFCAnyHandle openingRep = file.CreateProductDefinitionShape(IFCLabel.Create(), IFCLabel.Create(), representations);

                IFCAnyHandle openingPlacement = ExporterUtil.CopyLocalPlacement(file, originalPlacement);
                IFCLabel guid = IFCLabel.CreateGUID();
                IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                IFCLabel openingName = NamingUtil.GetNameOverride(element, NamingUtil.CreateIFCName(exporterIFC, openingNumber++));
                IFCLabel elementId = NamingUtil.CreateIFCElementId(element);
                IFCAnyHandle openingElement = file.CreateOpeningElement(guid, ownerHistory,
                   openingName, IFCLabel.Create(), openingObjectType, openingPlacement, openingRep, elementId);
                wrapper.AddElement(openingElement, setter, extraParams, true);
                if (exporterIFC.ExportBaseQuantities && (extraParams != null))
                    ExporterIFCUtils.CreateOpeningQuantities(exporterIFC, openingElement, extraParams);

                IFCLabel voidGuid = IFCLabel.CreateGUID();
                file.CreateRelVoidsElement(voidGuid, ownerHistory, IFCLabel.Create(), IFCLabel.Create(), elementHandle, openingElement);
            }
        }
Beispiel #43
0
        /// <summary>
        /// Exports a ramp to IfcRamp, without decomposing into separate runs and landings.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="ifcEnumType">The ramp type.</param>
        /// <param name="ramp">The ramp element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="numFlights">The number of flights for a multistory ramp.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportRamp(ExporterIFC exporterIFC, string ifcEnumType, Element ramp, GeometryElement geometryElement,
                                      int numFlights, IFCProductWrapper productWrapper)
        {
            if (ramp == null || geometryElement == null)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, ramp))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(placementSetter.GetPlacement());

                        ElementId           categoryId          = CategoryUtil.GetSafeCategoryId(ramp);
                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions();
                        IFCAnyHandle        representation      = RepresentationUtil.CreateBRepProductDefinitionShape(ramp.Document.Application,
                                                                                                                      exporterIFC, ramp, categoryId, geometryElement, bodyExporterOptions, null, ecData);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation))
                        {
                            ecData.ClearOpenings();
                            return;
                        }

                        string       containedRampGuid           = ExporterIFCUtils.CreateSubElementGUID(ramp, (int)IFCRampSubElements.ContainedRamp);
                        IFCAnyHandle ownerHistory                = exporterIFC.GetOwnerHistoryHandle();
                        string       origRampName                = exporterIFC.GetName();
                        string       rampName                    = NamingUtil.GetNameOverride(ramp, origRampName);
                        string       rampDescription             = NamingUtil.GetDescriptionOverride(ramp, null);
                        string       rampObjectType              = NamingUtil.GetObjectTypeOverride(ramp, NamingUtil.CreateIFCObjectName(exporterIFC, ramp));
                        IFCAnyHandle containedRampLocalPlacement = ExporterUtil.CopyLocalPlacement(file, ecData.GetLocalPlacement());
                        string       elementTag                  = NamingUtil.CreateIFCElementId(ramp);
                        IFCRampType  rampType                    = GetIFCRampType(ifcEnumType);

                        List <IFCAnyHandle> components       = new List <IFCAnyHandle>();
                        IFCAnyHandle        containedRampHnd = IFCInstanceExporter.CreateRamp(file, containedRampGuid, ownerHistory, rampName,
                                                                                              rampDescription, rampObjectType, containedRampLocalPlacement, representation, elementTag, rampType);
                        components.Add(containedRampHnd);
                        productWrapper.AddElement(containedRampHnd, placementSetter.GetLevelInfo(), ecData, false);

                        string       guid           = ExporterIFCUtils.CreateGUID(ramp);
                        IFCAnyHandle localPlacement = ecData.GetLocalPlacement();

                        IFCAnyHandle rampHnd = IFCInstanceExporter.CreateRamp(file, guid, ownerHistory, rampName,
                                                                              rampDescription, rampObjectType, localPlacement, null, elementTag, rampType);

                        productWrapper.AddElement(rampHnd, placementSetter.GetLevelInfo(), ecData, LevelUtil.AssociateElementToLevel(ramp));

                        StairRampContainerInfo stairRampInfo = new StairRampContainerInfo(rampHnd, components, null);
                        ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(ramp.Id, stairRampInfo);

                        ExportMultistoryRamp(exporterIFC, ramp, numFlights,
                                             ownerHistory, localPlacement, containedRampLocalPlacement, representation,
                                             rampName, rampObjectType, rampDescription, elementTag, rampType,
                                             ecData, placementSetter, productWrapper);
                    }
                    PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, ramp, productWrapper);
                    tr.Commit();
                }
            }
        }
Beispiel #44
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 IFCProductWrapper.</param>
        public static void ExportRoofAsParts(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                    IFCAnyHandle localPlacement = setter.GetPlacement();

                    using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData())
                    {
                        extrusionCreationData.SetLocalPlacement(setter.GetPlacement());
                        extrusionCreationData.PossibleExtrusionAxes = IFCExtrusionAxes.TryXY;

                        IFCAnyHandle prodRepHnd = null;

                        string elementGUID = ExporterIFCUtils.CreateGUID(element);
                        string origElementName = exporterIFC.GetName();
                        string elementName = NamingUtil.GetNameOverride(element, origElementName);
                        string elementDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string elementObjectType = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                        string elementId = NamingUtil.CreateIFCElementId(element);

                        //need to convert the string to enum
                        string ifcEnumType = CategoryUtil.GetIFCEnumTypeName(exporterIFC, element);
                        IFCAnyHandle roofHandle = IFCInstanceExporter.CreateRoof(file, elementGUID, ownerHistory, elementName, elementDescription, elementObjectType, localPlacement, prodRepHnd, elementId, GetIFCRoofType(ifcEnumType));

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

                        productWrapper.AddElement(roofHandle, setter, extrusionCreationData, LevelUtil.AssociateElementToLevel(element));

                        OpeningUtil.CreateOpeningsIfNecessary(roofHandle, element, extrusionCreationData, exporterIFC, extrusionCreationData.GetLocalPlacement(), setter, productWrapper);

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);
                    }
                    transaction.Commit();
                }
            }
        }
Beispiel #45
0
        /// <summary>
        /// Exports an element to IFC footing.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="ifcEnumType">
        /// The string value represents the IFC type.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportFooting(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement,
           string ifcEnumType, IFCProductWrapper productWrapper)
        {
            // export parts or not
            bool exportParts = PartExporter.CanExportParts(element);
            if (exportParts && !PartExporter.CanExportElementInPartExport(element, element.Level.Id, false))
                return;

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {                      
                        ecData.SetLocalPlacement(setter.GetPlacement());
                      
                        IFCAnyHandle prodRep = null;
                        if (!exportParts)
                        {
                            ElementId catId = CategoryUtil.GetSafeCategoryId(element);

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

                        string instanceGUID = ExporterIFCUtils.CreateGUID(element);
                        string origInstanceName = exporterIFC.GetName();
                        string instanceName = NamingUtil.GetNameOverride(element, origInstanceName);
                        string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceObjectType = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                        string instanceElemId = NamingUtil.CreateIFCElementId(element);
                        Toolkit.IFCFootingType footingType = GetIFCFootingType(element, ifcEnumType);

                        IFCAnyHandle footing = IFCInstanceExporter.CreateFooting(file, instanceGUID, exporterIFC.GetOwnerHistoryHandle(),
                            instanceName, instanceDescription, instanceObjectType, ecData.GetLocalPlacement(), prodRep, instanceElemId, footingType);

                        if (exportParts)
                        {
                            PartExporter.ExportHostPart(exporterIFC, element, footing, productWrapper, setter, setter.GetPlacement(), null);
                        }

                        productWrapper.AddElement(footing, setter, ecData, LevelUtil.AssociateElementToLevel(element));

                        OpeningUtil.CreateOpeningsIfNecessary(footing, element, ecData, exporterIFC, ecData.GetLocalPlacement(), setter, productWrapper);

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

                tr.Commit();
            }
        }
Beispiel #46
0
        /// <summary>
        /// Exports a roof to IfcRoof.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="ifcEnumType">The roof type.</param>
        /// <param name="roof">The roof element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportRoof(ExporterIFC exporterIFC, string ifcEnumType, Element roof, GeometryElement geometryElement, 
            IFCProductWrapper productWrapper)
        {
            if (roof == null || geometryElement == null)
                return;

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, roof))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.PossibleExtrusionAxes = IFCExtrusionAxes.TryZ;
                        ecData.AreInnerRegionsOpenings = true;
                        ecData.SetLocalPlacement(placementSetter.GetPlacement());

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(roof);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                        IFCAnyHandle representation = RepresentationUtil.CreateBRepProductDefinitionShape(roof.Document.Application, exporterIFC, roof,
                            categoryId, geometryElement, bodyExporterOptions, null, ecData);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation))
                        {
                            ecData.ClearOpenings();
                            return;
                        }

                        bool exportSlab = ecData.ScaledLength > MathUtil.Eps();

                        string guid = ExporterIFCUtils.CreateGUID(roof);
                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                        string origRoofName = exporterIFC.GetName();
                        string roofName = NamingUtil.GetNameOverride(roof, origRoofName);
                        string roofDescription = NamingUtil.GetDescriptionOverride(roof, null);
                        string roofObjectType = NamingUtil.GetObjectTypeOverride(roof, NamingUtil.CreateIFCObjectName(exporterIFC, roof));
                        IFCAnyHandle localPlacement = ecData.GetLocalPlacement();
                        string elementTag = NamingUtil.CreateIFCElementId(roof);
                        IFCRoofType roofType = GetIFCRoofType(ifcEnumType);

                        IFCAnyHandle roofHnd = IFCInstanceExporter.CreateRoof(file, guid, ownerHistory, roofName, roofDescription,
                            roofObjectType, localPlacement, exportSlab ? null : representation, elementTag, roofType);

                        productWrapper.AddElement(roofHnd, placementSetter.GetLevelInfo(), ecData, LevelUtil.AssociateElementToLevel(roof));

                        if (exportSlab)
                        {
                            string slabGUID = ExporterIFCUtils.CreateSubElementGUID(roof, (int)IFCRoofSubElements.RoofSlabStart);
                            string slabName = roofName + ":1";
                            IFCAnyHandle slabLocalPlacementHnd = ExporterUtil.CopyLocalPlacement(file, localPlacement);

                            IFCAnyHandle slabHnd = IFCInstanceExporter.CreateSlab(file, slabGUID, ownerHistory, slabName,
                               roofDescription, roofObjectType, slabLocalPlacementHnd, representation, elementTag, IFCSlabType.Roof);
                            OpeningUtil.CreateOpeningsIfNecessary(slabHnd, roof, ecData, exporterIFC, slabLocalPlacementHnd,
                                placementSetter, productWrapper);

                            ExporterUtil.RelateObject(exporterIFC, roofHnd, slabHnd);

                            productWrapper.AddElement(slabHnd, placementSetter.GetLevelInfo(), ecData, false);
                        }
                    }
                    tr.Commit();
                }
            }
        }
Beispiel #47
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();
                    }
                }
            }
        }
 /// <summary>
 /// Add a generic element to the wrapper, with associated setter and extrusion data information, and create associated internal property sets if option is set.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="handle">The element handle.</param>
 /// <param name="setter">The placement setter.</param>
 /// <param name="data">The extrusion creation data (can be null.)</param>
 /// <param name="relateToLevel">Relate to the level in the setter, or not.</param>
 public void AddElement(Element element, IFCAnyHandle handle, IFCPlacementSetter setter, IFCExtrusionCreationData data, bool relateToLevel)
 {
     m_InternalWrapper.AddElement(handle, setter, data, relateToLevel);
     RegisterHandleWithElement(element, handle);
 }
        /// <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 IFCProductWrapper.
        /// </param>
        /// <returns>
        /// True if the floor is exported successfully, false otherwise.
        /// </returns>
        public static void ExportFloor(ExporterIFC exporterIFC, Floor floor, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            if (geometryElement == null)
                return;

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCTransformSetter transformSetter = IFCTransformSetter.Create())
                {
                    using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, floor))
                    {
                        IFCAnyHandle localPlacement = placementSetter.GetPlacement();
                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

                        string ifcEnumType = CategoryUtil.GetIFCEnumTypeName(exporterIFC, floor);

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

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

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

                        bool exportedAsExtrusion = ExporterIFCUtils.ExportSlabAsExtrusion(exporterIFC, floor, geometryElement,
                              transformSetter, localPlacement, out localPlacements, out reps, out extrusionLoops, out loopExtraParams, floorPlane);
                        // We will use the ExtrusionAnalyzer when it is ready.
                        //            XYZ extrusionDirection = { 0, 0, -1 };
                        //            XYZ modelOrigin = { 0, 0, 0 };
                        //            XYZ floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                        //            XYZ floorDir = floor.GetNormalAtVerticalProjectionPoint(floorOrigin, FloorFace.Top);
                        //            Plane floorPlane(floorDir, floorOrigin);          
                        //            ExtrusionAnalyzer floorExtrusion = 
                        //                ExtrusionAnalyzer.Create(geometryElement, floorPlane, extrusionDirection);

                        if (!exportedAsExtrusion)
                        {
                            IFCAnyHandle bodyRep = null;
                            IList<GeometryObject> geomObjects = new List<GeometryObject>();
                            geomObjects.Add(geometryElement);
                            bodyRep = BodyExporter.ExportBody(floor.Document.Application, exporterIFC, catId, geomObjects, true, null);
                            if (bodyRep == null || !bodyRep.HasValue)
                            {
                                tr.Commit();
                                return;
                            }

                            IFCAnyHandle prodDefHnd = file.CreateProductDefinitionShape(bodyRep);
                            if (!prodDefHnd.HasValue)
                                return;

                            reps.Add(prodDefHnd);
                        }

                        // Create the slab from either the extrusion or the BRep information.
                        IFCLabel ifcGUID = IFCLabel.CreateGUID(floor);

                        IList<IFCAnyHandle> slabHnds = new List<IFCAnyHandle>();
                        int numReps = reps.Count;
                        for (int ii = 0; ii < numReps; ii++)
                        {
                            IFCLabel ifcName = NamingUtil.GetNameOverride(floor, NamingUtil.CreateIFCName(exporterIFC, ii == 0 ? -1 : ii + 1));
                            IFCLabel ifcDescription = NamingUtil.GetDescriptionOverride(floor, IFCLabel.Create());
                            IFCLabel ifcObjectType = NamingUtil.GetObjectTypeOverride(floor, exporterIFC.GetFamilyNameFromExportState());
                            IFCLabel ifcElemId = NamingUtil.CreateIFCElementId(floor);

                            IFCLabel currentGUID = (ii == 0) ? ifcGUID : IFCLabel.CreateGUID();
                            IFCAnyHandle localPlacementHnd = exportedAsExtrusion ? localPlacements[ii] : localPlacement;

                            IFCAnyHandle slabHnd = file.CreateSlab(currentGUID,
                               ownerHistory,
                               ifcName,
                               ifcDescription,
                               ifcObjectType,
                               localPlacementHnd,
                               ifcElemId,
                               ifcEnumType,
                               reps[ii]);

                            if (!slabHnd.HasValue)
                                return;

                            slabHnds.Add(slabHnd);
                        }

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

                        if (exportedAsExtrusion)
                            ExporterIFCUtils.ExportExtrudedSlabOpenings(exporterIFC, floor, placementSetter,
                               localPlacements[0], slabHnds, extrusionLoops, floorPlane, productWrapper);

                        ExporterIFCUtils.CreateGenericElementPropertySet(exporterIFC, floor, productWrapper);

                        ExporterIFCUtils.ExportHostObject(exporterIFC, floor, geometryElement, productWrapper);
                    }
                }
                tr.Commit();
            }
        }
Beispiel #50
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 IFCProductWrapper object.</param>
        public static void ExportPart(ExporterIFC exporterIFC, Element partElement, IFCProductWrapper productWrapper,
                                      IFCPlacementSetter placementSetter, IFCAnyHandle originalPlacement, IFCRange range, IFCExtrusionAxes ifcExtrusionAxes,
                                      Element hostElement, ElementId overrideLevelId, bool asBuildingElement)
        {
            if (!ElementFilteringUtil.IsElementVisible(ExporterCacheManager.ExportOptionsCache.FilterViewForExport, partElement))
            {
                return;
            }

            Part part = partElement as Part;

            if (part == null)
            {
                return;
            }

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

            ElementId partExportLevel = null;

            if (standaloneExport || asBuildingElement)
            {
                if (partElement.Level != null)
                {
                    partExportLevel = partElement.Level.Id;
                }
            }
            else
            {
                if (part.OriginalCategoryId != hostElement.Category.Id)
                {
                    return;
                }
                partExportLevel = hostElement.Level.Id;
            }
            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 = IFCPlacementSetter.Create(exporterIFC, partElement, null, orientationTrf, partExportLevel);
                        partPlacement             = standalonePlacementSetter.GetPlacement();
                    }
                    else
                    {
                        partPlacement = ExporterUtil.CopyLocalPlacement(file, originalPlacement);
                    }

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

                    SolidMeshGeometryInfo solidMeshInfo;
                    if (validRange)
                    {
                        solidMeshInfo = GeometryUtil.GetClippedSolidMeshGeometry(geometryElement, range);
                        if (solidMeshInfo.GetSolids().Count == 0 && solidMeshInfo.GetMeshes().Count == 0)
                        {
                            return;
                        }
                    }
                    else
                    {
                        solidMeshInfo = GeometryUtil.GetSolidMeshGeometry(geometryElement, Transform.Identity);
                    }

                    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);

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

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

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

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

                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

                        string partGUID        = ExporterIFCUtils.CreateGUID(partElement);
                        string origPartName    = NamingUtil.CreateIFCName(exporterIFC, -1);
                        string partName        = NamingUtil.GetNameOverride(partElement, origPartName);
                        string partDescription = NamingUtil.GetDescriptionOverride(partElement, null);
                        string partObjectType  = NamingUtil.GetObjectTypeOverride(partElement, NamingUtil.CreateIFCObjectName(exporterIFC, partElement));
                        string partElemId      = NamingUtil.CreateIFCElementId(partElement);

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

                            case IFCExportType.ExportCovering:
                                IFCCoveringType coveringType = CeilingExporter.GetIFCCoveringType(hostElement, ifcEnumType);
                                ifcPart = IFCInstanceExporter.CreateCovering(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                             extrusionCreationData.GetLocalPlacement(), prodRep, partElemId, coveringType);
                                break;

                            case IFCExportType.ExportFooting:
                                IFCFootingType footingType = FootingExporter.GetIFCFootingType(hostElement, ifcEnumType);
                                ifcPart = IFCInstanceExporter.CreateFooting(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                            extrusionCreationData.GetLocalPlacement(), prodRep, partElemId, footingType);
                                break;

                            case IFCExportType.ExportRoof:
                                IFCRoofType roofType = RoofExporter.GetIFCRoofType(ifcEnumType);
                                ifcPart = IFCInstanceExporter.CreateRoof(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, partElemId, roofType);
                                break;

                            case IFCExportType.ExportSlab:
                                IFCSlabType slabType = FloorExporter.GetIFCSlabType(ifcEnumType);
                                ifcPart = IFCInstanceExporter.CreateSlab(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, partElemId, slabType);
                                break;

                            case IFCExportType.ExportWall:
                                ifcPart = IFCInstanceExporter.CreateWallStandardCase(file, partGUID, ownerHistory, partName, partDescription,
                                                                                     partObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, partElemId);
                                break;

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

                        productWrapper.AddElement(ifcPart, standaloneExport || asBuildingElement ? standalonePlacementSetter : placementSetter, extrusionCreationData, standaloneExport || asBuildingElement);

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

                        CategoryUtil.CreateMaterialAssociations(partElement.Document, exporterIFC, ifcPart, bodyData.MaterialIds);

                        transaction.Commit();
                    }
                }
            }
            finally
            {
                if (standalonePlacementSetter != null)
                {
                    standalonePlacementSetter.Dispose();
                }
            }
        }