Пример #1
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);
        }
Пример #2
0
        /// <summary>
        /// Export the roof to IfcRoof containing its parts.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The roof element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportRoofAsParts(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

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

                    IFCAnyHandle prodRepHnd = null;

                    string elementGUID        = GUIDUtil.CreateGUID(element);
                    string elementName        = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                    string elementDescription = NamingUtil.GetDescriptionOverride(element, null);
                    string elementObjectType  = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                    string elementTag         = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));

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

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

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

                    transaction.Commit();
                }
            }
        }
        /// <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);
        }
Пример #4
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 data.</param>
        /// <param name="extraParams">The extrusion creation data.</param>
        /// <param name="offsetTransform">The offset transform from ExportBody, or the identity transform.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="originalPlacement">The original placement handle.</param>
        /// <param name="setter">The PlacementSetter.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        private static void CreateOpeningsIfNecessaryBase(IFCAnyHandle elementHandle, Element element, IList<IFCExtrusionData> info,
           IFCExtrusionCreationData extraParams, Transform offsetTransform, ExporterIFC exporterIFC,
           IFCAnyHandle originalPlacement, IFCPlacementSetter setter, ProductWrapper wrapper)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(elementHandle))
                return;

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

            using (IFCTransformSetter transformSetter = IFCTransformSetter.Create())
            {
                if (offsetTransform != null)
                    transformSetter.Initialize(exporterIFC, offsetTransform.Inverse);

            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 = GUIDUtil.CreateGUID();
                IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                string openingName = NamingUtil.GetIFCNamePlusIndex(element, openingNumber++);
                string elementId = NamingUtil.CreateIFCElementId(element);
                IFCAnyHandle openingElement = IFCInstanceExporter.CreateOpeningElement(file, guid, ownerHistory,
                   openingName, null, openingObjectType, openingPlacement, openingRep, elementId);
                wrapper.AddElement(null, openingElement, setter, extraParams, true);
                if (ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities && (extraParams != null))
                    ExporterIFCUtils.CreateOpeningQuantities(exporterIFC, openingElement, extraParams);

                string voidGuid = GUIDUtil.CreateGUID();
                IFCInstanceExporter.CreateRelVoidsElement(file, voidGuid, ownerHistory, null, null, elementHandle, openingElement);
            }
        }
        }
        /// <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 ProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        protected static bool ExportInsulation(ExporterIFC exporterIFC, Element element,
                                               GeometryElement geometryElement, ProductWrapper 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, null, null, ExporterUtil.GetBaseLevelIdForElement(element)))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(placementSetter.GetPlacement());

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

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

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

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

                        IFCAnyHandle localPlacement = ecData.GetLocalPlacement();
                        string       elementTag     = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));

                        IFCAnyHandle insulation = IFCInstanceExporter.CreateCovering(file, guid,
                                                                                     ownerHistory, name, description, objectType, localPlacement, representation, elementTag, IFCCoveringType.Insulation);
                        ExporterCacheManager.ElementToHandleCache.Register(element.Id, insulation);

                        productWrapper.AddElement(element, insulation, placementSetter.GetLevelInfo(), ecData, true);

                        ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, exporterIFC, element);
                        CategoryUtil.CreateMaterialAssociation(exporterIFC, insulation, matId);
                    }
                }
                tr.Commit();
                return(true);
            }
        }
Пример #6
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="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="originalPlacement">
        /// The original placement handle.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <param name="wrapper">
        /// The ProductWrapper.
        /// </param>
        public static void CreateOpeningsIfNecessary(IFCAnyHandle elementHandle, Element element, IList<IFCExtrusionData> info,
            ExporterIFC exporterIFC, IFCAnyHandle originalPlacement,
            IFCPlacementSetter setter, ProductWrapper wrapper)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(elementHandle))
                return;

            using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
            {
                CreateOpeningsIfNecessaryBase(elementHandle, element, info, extraParams, exporterIFC, originalPlacement, setter, wrapper);
            }
        }
Пример #7
0
        /// <summary>
        /// Exports an element as building element proxy.
        /// </summary>
        /// <remarks>
        /// This function is called from the Export function, but can also be called directly if you do not
        /// want CreateInternalPropertySets to be called.
        /// </remarks>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>The handle if created, null otherwise.</returns>
        public static IFCAnyHandle ExportBuildingElementProxy(ExporterIFC exporterIFC, Element element,
                                                              GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            if (element == null || geometryElement == null)
            {
                return(null);
            }

            IFCFile      file = exporterIFC.GetFile();
            IFCAnyHandle buildingElementProxy = null;

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

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

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

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

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

                        IFCAnyHandle localPlacement = ecData.GetLocalPlacement();
                        string       elementTag     = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));

                        buildingElementProxy = IFCInstanceExporter.CreateBuildingElementProxy(file, guid,
                                                                                              ownerHistory, name, description, objectType, localPlacement, representation, elementTag, null);

                        productWrapper.AddElement(element, buildingElementProxy, placementSetter.GetLevelInfo(), ecData, true);
                    }
                    tr.Commit();
                }
            }

            return(buildingElementProxy);
        }
        /// <summary>
        /// Exports an element as an IFC assembly with its members.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="assemblyElem">The element to be exported as IFC assembly.</param>
        /// <param name="memberIds">The member element ids.</param>
        /// <param name="assemblyType">The IFC assembly type.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        static void ExportAssemblyInstanceWithMembers(ExporterIFC exporterIFC, Element assemblyElem,
                                                      ICollection <ElementId> memberIds, IFCElementAssemblyType assemblyType, ProductWrapper productWrapper)
        {
            HashSet <IFCAnyHandle> memberHnds = new HashSet <IFCAnyHandle>();

            foreach (ElementId memberId in memberIds)
            {
                IFCAnyHandle memberHnd = ExporterCacheManager.ElementToHandleCache.Find(memberId);
                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(memberHnd))
                {
                    memberHnds.Add(memberHnd);
                }
            }

            if (memberHnds.Count == 0)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter placementSetter = IFCPlacementSetter.Create(exporterIFC, assemblyElem, null, null, ExporterUtil.GetBaseLevelIdForElement(assemblyElem)))
                {
                    IFCAnyHandle ownerHistory   = exporterIFC.GetOwnerHistoryHandle();
                    IFCAnyHandle localPlacement = placementSetter.GetPlacement();

                    string guid        = GUIDUtil.CreateGUID(assemblyElem);
                    string name        = NamingUtil.GetIFCName(assemblyElem);
                    string description = NamingUtil.GetDescriptionOverride(assemblyElem, null);
                    string objectType  = NamingUtil.GetObjectTypeOverride(assemblyElem, exporterIFC.GetFamilyName());
                    string elementTag  = NamingUtil.CreateIFCElementId(assemblyElem);

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

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

                    string aggregateGuid = GUIDUtil.CreateSubElementGUID(assemblyElem, (int)IFCAssemblyInstanceSubElements.RelAggregates);
                    IFCInstanceExporter.CreateRelAggregates(file, aggregateGuid, ownerHistory, null, null, assemblyInstanceHnd, memberHnds);

                    ExporterCacheManager.ElementsInAssembliesCache.UnionWith(memberHnds);

                    // Update member local placements to be relative to the assembly.
                    SetLocalPlacementsRelativeToAssembly(exporterIFC, localPlacement, memberHnds);
                }
                tr.Commit();
            }
        }
Пример #9
0
        /// <summary>
        /// Export all the parts of the host element.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="hostElement">The host element having parts to export.</param>
        /// <param name="hostHandle">The host element handle.</param>
        /// <param name="originalWrapper">The ProductWrapper object.</param>
        public static void ExportHostPart(ExporterIFC exporterIFC, Element hostElement, IFCAnyHandle hostHandle,
                                          ProductWrapper originalWrapper, IFCPlacementSetter placementSetter, IFCAnyHandle originalPlacement, ElementId overrideLevelId)
        {
            using (ProductWrapper subWrapper = ProductWrapper.Create(exporterIFC, true))
            {
                List <ElementId> associatedPartsList = PartUtils.GetAssociatedParts(hostElement.Document, hostElement.Id, false, true).ToList();
                if (associatedPartsList.Count == 0)
                {
                    return;
                }

                bool isWallOrColumn   = IsHostWallOrColumn(exporterIFC, hostElement);
                bool hasOverrideLevel = overrideLevelId != null && overrideLevelId != ElementId.InvalidElementId;

                IFCExtrusionAxes ifcExtrusionAxes = GetDefaultExtrusionAxesForHost(exporterIFC, hostElement);

                // Split parts if wall or column is split by level, and then export; otherwise, export parts normally.
                if (isWallOrColumn && hasOverrideLevel && ExporterCacheManager.ExportOptionsCache.WallAndColumnSplitting)
                {
                    if (!ExporterCacheManager.HostPartsCache.HasRegistered(hostElement.Id))
                    {
                        SplitParts(exporterIFC, hostElement, associatedPartsList); // Split parts and associate them with host.
                    }
                    // Find and export the parts that are split by specific level.
                    List <KeyValuePair <Part, IFCRange> > splitPartRangeList = new List <KeyValuePair <Part, IFCRange> >();
                    splitPartRangeList = ExporterCacheManager.HostPartsCache.Find(hostElement.Id, overrideLevelId);

                    foreach (KeyValuePair <Part, IFCRange> partRange in splitPartRangeList)
                    {
                        PartExporter.ExportPart(exporterIFC, partRange.Key, subWrapper, placementSetter, originalPlacement, partRange.Value, ifcExtrusionAxes, hostElement, overrideLevelId, false);
                    }
                }
                else
                {
                    foreach (ElementId partId in associatedPartsList)
                    {
                        Part part = hostElement.Document.GetElement(partId) as Part;
                        PartExporter.ExportPart(exporterIFC, part, subWrapper, placementSetter, originalPlacement, null, ifcExtrusionAxes, hostElement, overrideLevelId, false);
                    }
                }

                // Create the relationship of Host and Parts.
                ICollection <IFCAnyHandle> relatedElementIds = subWrapper.GetAllObjects();
                if (relatedElementIds.Count > 0)
                {
                    string guid = GUIDUtil.CreateGUID();
                    HashSet <IFCAnyHandle> relatedElementIdSet = new HashSet <IFCAnyHandle>(relatedElementIds);
                    IFCInstanceExporter.CreateRelAggregates(exporterIFC.GetFile(), guid, exporterIFC.GetOwnerHistoryHandle(), null, null, hostHandle, relatedElementIdSet);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Creates openings associated with an extrusion, if there are any.
        /// </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 data.</param>
        /// <param name="offsetTransform">The offset transform from ExportBody, or the identity transform.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="originalPlacement">The original placement handle.</param>
        /// <param name="setter">The PlacementSetter.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        public static void CreateOpeningsIfNecessary(IFCAnyHandle elementHandle, Element element, IList <IFCExtrusionData> info, Transform offsetTransform,
                                                     ExporterIFC exporterIFC, IFCAnyHandle originalPlacement,
                                                     IFCPlacementSetter setter, ProductWrapper wrapper)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(elementHandle))
            {
                return;
            }

            using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
            {
                CreateOpeningsIfNecessaryBase(elementHandle, element, info, extraParams, offsetTransform, exporterIFC, originalPlacement, setter, wrapper);
            }
        }
Пример #11
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();
            }
        }
Пример #12
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="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, Mullion mullion, GeometryElement geometryElement,
                                  IFCAnyHandle localPlacement, IFCPlacementSetter setter, ProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCPlacementSetter mullionSetter = IFCPlacementSetter.Create(exporterIFC, mullion, null, null, ExporterUtil.GetBaseLevelIdForElement(mullion)))
            {
                using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                {
                    IFCAnyHandle mullionPlacement = mullionSetter.GetPlacement();

                    Transform relTrf     = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(localPlacement, mullionPlacement);
                    Transform inverseTrf = relTrf.Inverse;

                    IFCAnyHandle mullionRelativePlacement = ExporterUtil.CreateAxis2Placement3D(file, inverseTrf.Origin, inverseTrf.BasisZ, inverseTrf.BasisX);
                    IFCAnyHandle mullionLocalPlacement    = IFCInstanceExporter.CreateLocalPlacement(file, localPlacement, mullionRelativePlacement);

                    extraParams.SetLocalPlacement(mullionLocalPlacement);

                    ElementId catId = CategoryUtil.GetSafeCategoryId(mullion);

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

                    string       elemGUID       = GUIDUtil.CreateGUID(mullion);
                    IFCAnyHandle ownerHistory   = exporterIFC.GetOwnerHistoryHandle();
                    string       elemObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, mullion);
                    string       name           = NamingUtil.GetNameOverride(mullion, elemObjectType);
                    string       description    = NamingUtil.GetDescriptionOverride(mullion, null);
                    string       objectType     = NamingUtil.GetObjectTypeOverride(mullion, elemObjectType);
                    string       elemTag        = NamingUtil.GetTagOverride(mullion, NamingUtil.CreateIFCElementId(mullion));

                    IFCAnyHandle mullionHnd = IFCInstanceExporter.CreateMember(file, elemGUID, ownerHistory, name, description, objectType,
                                                                               mullionLocalPlacement, repHnd, elemTag);
                    ExporterCacheManager.HandleToElementCache.Register(mullionHnd, mullion.Id);

                    productWrapper.AddElement(mullion, mullionHnd, mullionSetter, extraParams, false);

                    ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, exporterIFC, mullion);
                    CategoryUtil.CreateMaterialAssociation(exporterIFC, mullionHnd, matId);
                }
            }
        }
        /// <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="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, Mullion mullion, GeometryElement geometryElement,
           IFCAnyHandle localPlacement, IFCPlacementSetter setter, ProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCPlacementSetter mullionSetter = IFCPlacementSetter.Create(exporterIFC, mullion, null, null, ExporterUtil.GetBaseLevelIdForElement(mullion)))
            {
                using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                {
                    IFCAnyHandle mullionPlacement = mullionSetter.GetPlacement();

                    Transform relTrf = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(localPlacement, mullionPlacement);
                    Transform inverseTrf = relTrf.Inverse;

                    IFCAnyHandle mullionRelativePlacement = ExporterUtil.CreateAxis2Placement3D(file, inverseTrf.Origin, inverseTrf.BasisZ, inverseTrf.BasisX);
                	IFCAnyHandle mullionLocalPlacement = IFCInstanceExporter.CreateLocalPlacement(file, localPlacement, mullionRelativePlacement);

                    extraParams.SetLocalPlacement(mullionLocalPlacement);

                    ElementId catId = CategoryUtil.GetSafeCategoryId(mullion);

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

                    string elemGUID = GUIDUtil.CreateGUID(mullion);
                    IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                    string elemObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, mullion);
                    string name = NamingUtil.GetNameOverride(mullion, elemObjectType);
                    string description = NamingUtil.GetDescriptionOverride(mullion, null);
                    string objectType = NamingUtil.GetObjectTypeOverride(mullion, elemObjectType);
                    string elemTag = NamingUtil.GetTagOverride(mullion, NamingUtil.CreateIFCElementId(mullion));

                    IFCAnyHandle mullionHnd = IFCInstanceExporter.CreateMember(file, elemGUID, ownerHistory, name, description, objectType,
                       mullionLocalPlacement, repHnd, elemTag);
                    ExporterCacheManager.HandleToElementCache.Register(mullionHnd, mullion.Id);

                    productWrapper.AddElement(mullion, mullionHnd, mullionSetter, extraParams, false);

                    ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, exporterIFC, mullion);
                    CategoryUtil.CreateMaterialAssociation(exporterIFC, mullionHnd, matId);
                }
            }
        }
Пример #14
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 (!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);
            }
        }
Пример #15
0
        /// <summary>
        /// Export all the parts of the host element.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="hostElement">The host element having parts to export.</param>
        /// <param name="hostHandle">The host element handle.</param>
        /// <param name="originalWrapper">The IFCProductWrapper object.</param>
        public static void ExportHostPart(ExporterIFC exporterIFC, Element hostElement, IFCAnyHandle hostHandle,
            IFCProductWrapper originalWrapper, IFCPlacementSetter placementSetter, IFCAnyHandle originalPlacement, ElementId overrideLevelId)
        {
            using (IFCProductWrapper subWrapper = IFCProductWrapper.Create(exporterIFC, true))
            {
                List<ElementId> associatedPartsList = PartUtils.GetAssociatedParts(hostElement.Document, hostElement.Id, false, true).ToList();
                if (associatedPartsList.Count == 0)
                    return;

                bool isWallOrColumn = IsHostWallOrColumn(exporterIFC, hostElement);
                bool hasOverrideLevel = overrideLevelId != null && overrideLevelId != ElementId.InvalidElementId;

                IFCExtrusionAxes ifcExtrusionAxes = GetDefaultExtrusionAxesForHost(exporterIFC, hostElement);

                // Split parts if wall or column is split by level, and then export; otherwise, export parts normally.
                if (isWallOrColumn && hasOverrideLevel && ExporterCacheManager.ExportOptionsCache.WallAndColumnSplitting)
                {
                    if (!ExporterCacheManager.HostPartsCache.HasRegistered(hostElement.Id))                
                        SplitParts(exporterIFC, hostElement, associatedPartsList); // Split parts and associate them with host.                   

                    // Find and export the parts that are split by specific level.
                    List<KeyValuePair<Part, IFCRange>> splitPartRangeList = new List<KeyValuePair<Part, IFCRange>>();
                    splitPartRangeList = ExporterCacheManager.HostPartsCache.Find(hostElement.Id, overrideLevelId);

                    foreach (KeyValuePair<Part, IFCRange> partRange in splitPartRangeList)
                    {
                        PartExporter.ExportPart(exporterIFC, partRange.Key, subWrapper, placementSetter, originalPlacement, partRange.Value, ifcExtrusionAxes, hostElement, overrideLevelId, false);
                    }
                }
                else
                {
                    foreach (ElementId partId in associatedPartsList)
                    {
                        Part part = hostElement.Document.GetElement(partId) as Part;
                        PartExporter.ExportPart(exporterIFC, part, subWrapper, placementSetter, originalPlacement, null, ifcExtrusionAxes, hostElement, overrideLevelId, false);
                    }
                }

                // Create the relationship of Host and Parts.
                ICollection<IFCAnyHandle> relatedElementIds = subWrapper.GetAllObjects();
                if (relatedElementIds.Count > 0)
                {
                    string guid = ExporterIFCUtils.CreateGUID();
                    HashSet<IFCAnyHandle> relatedElementIdSet = new HashSet<IFCAnyHandle>(relatedElementIds);
                    IFCInstanceExporter.CreateRelAggregates(exporterIFC.GetFile(), guid, exporterIFC.GetOwnerHistoryHandle(), null, null, hostHandle, relatedElementIdSet);
                }
            }
        }
Пример #16
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);
            }
        }
Пример #17
0
        /// <summary>
        /// Creates openings associated with an extrusion, if there are any.
        /// </summary>
        /// <param name="elementHandle">The element handle to create openings.</param>
        /// <param name="element">The element to create openings.</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 PlacementSetter.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        public static void CreateOpeningsIfNecessary(IFCAnyHandle elementHandle, Element element, IFCExtrusionCreationData extraParams,
                                                     Transform offsetTransform, ExporterIFC exporterIFC, IFCAnyHandle originalPlacement,
                                                     IFCPlacementSetter setter, ProductWrapper wrapper)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(elementHandle))
            {
                return;
            }

            ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

            IList <IFCExtrusionData> info = extraParams.GetOpenings();

            CreateOpeningsIfNecessaryBase(elementHandle, element, info, extraParams, offsetTransform, exporterIFC, originalPlacement, setter, wrapper);
            extraParams.ClearOpenings();
        }
Пример #18
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();
                }
            }
        }
Пример #19
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 ProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, Mullion mullion, GeometryElement geometryElement,
            IFCAnyHandle localPlacement, IFCExtrusionCreationData extraParams, IFCPlacementSetter setter, ProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCPlacementSetter mullionSetter = IFCPlacementSetter.Create(exporterIFC, mullion))
            {
                IFCAnyHandle mullionPlacement = mullionSetter.GetPlacement();

                Transform relTrf = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(localPlacement, mullionPlacement);
                Transform inverseTrf = relTrf.Inverse;

                IFCAnyHandle mullionRelativePlacement = ExporterUtil.CreateAxis2Placement3D(file, inverseTrf.Origin, inverseTrf.BasisZ, inverseTrf.BasisX);
                IFCAnyHandle mullionLocalPlacement = IFCInstanceExporter.CreateLocalPlacement(file, localPlacement, mullionRelativePlacement);

                extraParams.SetLocalPlacement(mullionLocalPlacement);

                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 = GUIDUtil.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,
                   mullionLocalPlacement, repHnd, elemId);
                productWrapper.AddElement(mullionHnd, mullionSetter, extraParams, false);

                ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, exporterIFC, mullion);
                CategoryUtil.CreateMaterialAssociation(mullion.Document, exporterIFC, mullionHnd, matId);
                PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, mullion, productWrapper);
            }
        }
Пример #20
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);
            }
        }
        /// <summary>
        /// Exports curtain object as one Brep.
        /// </summary>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="wallElement">
        /// The curtain wall element.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter object.
        /// </param>
        /// <param name="localPlacement">
        /// The local placement handle.
        /// </param>
        /// <returns>
        /// The handle.
        /// </returns>
        public static IFCAnyHandle ExportCurtainObjectCommonAsOneBRep(ICollection<ElementId> allSubElements, Element wallElement,
           ExporterIFC exporterIFC, IFCPlacementSetter setter, IFCAnyHandle localPlacement)
        {
            IFCAnyHandle prodDefRep = null;
            Document document = wallElement.Document;
            double eps = document.Application.VertexTolerance * exporterIFC.LinearScale;

            IFCFile file = exporterIFC.GetFile();
            IFCAnyHandle contextOfItems = exporterIFC.Get3DContextHandle("Body");

            IFCGeometryInfo info = IFCGeometryInfo.CreateFaceGeometryInfo(eps);

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

            // Want to make sure we don't accidentally add a mullion or curtain line more than once.
            HashSet<ElementId> alreadyVisited = new HashSet<ElementId>();

            Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions();
            foreach (ElementId subElemId in allSubElements)
            {
                Element subElem = wallElement.Document.GetElement(subElemId);
                GeometryElement geomElem = subElem.get_Geometry(geomOptions);
                if (geomElem == null)
                    continue;

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

                ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geomElem, XYZ.Zero, false);
                HashSet<IFCAnyHandle> faces = new HashSet<IFCAnyHandle>(info.GetSurfaces());
                IFCAnyHandle outer = IFCInstanceExporter.CreateClosedShell(file, faces);

                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(outer))
                    bodyItems.Add(RepresentationUtil.CreateFacetedBRep(exporterIFC, document, outer, ElementId.InvalidElementId));
            }

            if (bodyItems.Count == 0)
                return prodDefRep;

            ElementId catId = CategoryUtil.GetSafeCategoryId(wallElement);
            IFCAnyHandle shapeRep = RepresentationUtil.CreateBRepRep(exporterIFC, wallElement, catId, contextOfItems, bodyItems);
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(shapeRep))
                return prodDefRep;

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

            IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, wallElement.get_Geometry(geomOptions), Transform.Identity);
            if (boundingBoxRep != null)
                shapeReps.Add(boundingBoxRep);

            prodDefRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
            return prodDefRep;
        }
        /// <summary>
        /// Creates IFC room/space/area item, not include boundaries. 
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="spatialElement">
        /// The spatial element.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <returns>
        /// True if created successfully, false otherwise.
        /// </returns>
        static bool CreateIFCSpace(ExporterIFC exporterIFC, SpatialElement spatialElement, ProductWrapper productWrapper, IFCPlacementSetter setter)
        {
            IList<CurveLoop> curveLoops = null;
            try
            {
                SpatialElementBoundaryOptions options = ExporterIFCUtils.GetSpatialElementBoundaryOptions(exporterIFC, spatialElement);
                curveLoops = ExporterIFCUtils.GetRoomBoundaryAsCurveLoopArray(spatialElement, options, true);
            }
            catch (Autodesk.Revit.Exceptions.InvalidOperationException)
            {
                //Some spatial elements are not placed that have no boundary loops. Don't export them.
                return false;
            }

            Autodesk.Revit.DB.Document document = spatialElement.Document;
            ElementId levelId = spatialElement.Level != null ? spatialElement.Level.Id : ElementId.InvalidElementId;
            double scale = exporterIFC.LinearScale;

            ElementId catId = spatialElement.Category != null ? spatialElement.Category.Id : ElementId.InvalidElementId;

            double dArea = 0.0;
            if (ParameterUtil.GetDoubleValueFromElement(spatialElement, BuiltInParameter.ROOM_AREA, out dArea))
                dArea *= (scale * scale);

            IFCLevelInfo levelInfo = exporterIFC.GetLevelInfo(levelId);

            string strSpaceNumber = null;
            string strSpaceName = null;
            string strSpaceDesc = null;

            bool isArea = spatialElement is Area;
            if (!isArea)
            {
                if (!ParameterUtil.GetStringValueFromElement(spatialElement, BuiltInParameter.ROOM_NUMBER, out strSpaceNumber))
                    strSpaceNumber = null;

                if (!ParameterUtil.GetStringValueFromElement(spatialElement, BuiltInParameter.ROOM_NAME, out strSpaceName))
                    strSpaceName = null;

                if (!ParameterUtil.GetStringValueFromElement(spatialElement, BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS, out strSpaceDesc))
                    strSpaceDesc = null;
            }
            else
            {
                // Default to true to preserve previous behavior.
                bool? exportGSADesignGrossArea = ExporterCacheManager.ExportOptionsCache.ExportGSAGrossDesignArea;
                if (!exportGSADesignGrossArea.HasValue || exportGSADesignGrossArea.Value)
                {
                    Element level = document.GetElement(levelId);
                    if (level != null)
                    {
                        strSpaceNumber = level.Name + " GSA Design Gross Area";
                    }
                }
            }

            string name = strSpaceNumber;
            string longName = strSpaceName;
            string desc = strSpaceDesc;

            IFCFile file = exporterIFC.GetFile();

            IFCAnyHandle localPlacement = setter.GetPlacement();
            ElementType elemType = document.GetElement(spatialElement.GetTypeId()) as ElementType;
            IFCInternalOrExternal internalOrExternal = CategoryUtil.IsElementExternal(spatialElement, true) ? IFCInternalOrExternal.External : IFCInternalOrExternal.Internal;

            double roomHeight = 0.0;

            roomHeight = GetHeight(spatialElement, scale, levelId, levelInfo);
            if (roomHeight <= 0.0)
                return false;

            double bottomOffset;
            ParameterUtil.GetDoubleValueFromElement(spatialElement, BuiltInParameter.ROOM_LOWER_OFFSET, out bottomOffset);

            XYZ zDir = new XYZ(0, 0, 1);
            XYZ orig = new XYZ(0, 0, levelInfo.Elevation + bottomOffset);

            Plane plane = new Plane(zDir, orig); // room calculated as level offset.

            GeometryElement geomElem = null;
            if (spatialElement is Autodesk.Revit.DB.Architecture.Room)
            {
                Autodesk.Revit.DB.Architecture.Room room = spatialElement as Autodesk.Revit.DB.Architecture.Room;
                geomElem = room.ClosedShell;
            }
            else if (spatialElement is Autodesk.Revit.DB.Mechanical.Space)
            {
                Autodesk.Revit.DB.Mechanical.Space space = spatialElement as Autodesk.Revit.DB.Mechanical.Space;
                geomElem = space.ClosedShell;
            }

            IFCAnyHandle spaceHnd = null;
            using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
            {
                extraParams.SetLocalPlacement(localPlacement);
                extraParams.PossibleExtrusionAxes = IFCExtrusionAxes.TryZ;

                using (IFCTransaction transaction2 = new IFCTransaction(file))
                {
                    IFCAnyHandle repHnd = null;
                    if (!ExporterCacheManager.ExportOptionsCache.Use2DRoomBoundaryForRoomVolumeCreation && geomElem != null)
                    {
                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                        bodyExporterOptions.TessellationLevel = BodyExporterOptions.BodyTessellationLevel.Coarse;
                        repHnd = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC, spatialElement,
                            catId, geomElem, bodyExporterOptions, null, extraParams);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd))
                            extraParams.ClearOpenings();
                    }
                    else
                    {
                        IFCAnyHandle shapeRep = ExtrusionExporter.CreateExtrudedSolidFromCurveLoop(exporterIFC, null, curveLoops, plane, zDir, roomHeight);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(shapeRep))
                            return false;
                        IFCAnyHandle styledItemHnd = BodyExporter.CreateSurfaceStyleForRepItem(exporterIFC, document,
                            shapeRep, ElementId.InvalidElementId);

                        HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
                        bodyItems.Add(shapeRep);
                        shapeRep = RepresentationUtil.CreateSweptSolidRep(exporterIFC, spatialElement, catId, exporterIFC.Get3DContextHandle("Body"), bodyItems, null);
                        IList<IFCAnyHandle> shapeReps = new List<IFCAnyHandle>();
                        shapeReps.Add(shapeRep);

                        IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geomElem, Transform.Identity);
                        if (boundingBoxRep != null)
                            shapeReps.Add(boundingBoxRep);

                        repHnd = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                    }

                    extraParams.ScaledHeight = roomHeight;
                    extraParams.ScaledArea = dArea;

                    string spatialElementName = NamingUtil.GetNameOverride(spatialElement, name);
                    string spatialElementDescription = NamingUtil.GetDescriptionOverride(spatialElement, desc);
                    string spatialElementObjectType = NamingUtil.GetObjectTypeOverride(spatialElement, null);

                    double? spaceElevationWithFlooring = null;
                    double elevationWithFlooring = 0.0;
                    if (ParameterUtil.GetDoubleValueFromElement(spatialElement, "IfcElevationWithFlooring", out elevationWithFlooring) == true)
                        spaceElevationWithFlooring = elevationWithFlooring;
                    spaceHnd = IFCInstanceExporter.CreateSpace(file, GUIDUtil.CreateGUID(spatialElement),
                                                  exporterIFC.GetOwnerHistoryHandle(),
                                                  spatialElementName,spatialElementDescription, spatialElementObjectType,
                                                  extraParams.GetLocalPlacement(), repHnd, longName, Toolkit.IFCElementComposition.Element,
                                                  internalOrExternal, spaceElevationWithFlooring);

                    transaction2.Commit();
                }

                productWrapper.AddSpace(spaceHnd, levelInfo, extraParams, true);
            }

            // Save room handle for later use/relationships
            ExporterCacheManager.SpatialElementHandleCache.Register(spatialElement.Id, spaceHnd);
            exporterIFC.RegisterSpatialElementHandle(spatialElement.Id, spaceHnd);

            // Find Ceiling as a Space boundary and keep the relationship in a cache for use later
            Boolean ret = getCeilingSpaceBoundary(spatialElement);

            if (!MathUtil.IsAlmostZero(dArea) && !(ExporterCacheManager.ExportOptionsCache.FileVersion == IFCVersion.IFCCOBIE) &&
                !ExporterCacheManager.ExportOptionsCache.ExportAs2x3CoordinationView2 && !ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities)
            {
                ExporterIFCUtils.CreatePreCOBIEGSAQuantities(exporterIFC, spaceHnd, "GSA Space Areas", (isArea ? "GSA Design Gross Area" : "GSA BIM Area"), dArea);
            }

            // Export BaseQuantities for SpatialElement
            if (ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities && !(ExporterCacheManager.ExportOptionsCache.FileVersion == IFCVersion.IFCCOBIE))
            {
                // Skip this step. The "standard" quantities will be exported at the end of export element process in exportElement (Exporter.cs)
                // ExporterIFCUtils.CreateNonCOBIERoomQuantities(exporterIFC, spaceHnd, spatialElement, dArea, roomHeight);
            }

            // Create general classification for Spatial element from ClassificationCode(s). This is not done here but rather at the end of exportElement process
            // ClassificationUtil.CreateClassification(exporterIFC, file, spatialElement, spaceHnd, "");

            // Export Classifications for SpatialElement for GSA/COBIE.
            if (ExporterCacheManager.ExportOptionsCache.FileVersion == IFCVersion.IFCCOBIE)
            {
                CreateCOBIESpaceClassifications(exporterIFC, file, spaceHnd, document.ProjectInformation, spatialElement);
            }

            return true;
        }
        /// <summary>
        /// Create IFC room/space/area item, not include boundaries. 
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="spatialElement">
        /// The spatial element.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <returns>
        /// True if created successfully, false otherwise.
        /// </returns>
        static void CreateIFCSpace(ExporterIFC exporterIFC, SpatialElement spatialElement, IFCProductWrapper productWrapper, IFCPlacementSetter setter)
        {
            Autodesk.Revit.DB.Document document = spatialElement.Document;
            ElementId levelId = spatialElement.Level != null ? spatialElement.Level.Id : ElementId.InvalidElementId;
            double scale = exporterIFC.LinearScale;

            ElementId catId = spatialElement.Category != null ? spatialElement.Category.Id : ElementId.InvalidElementId;

            double dArea = 0.0;

            Parameter param = spatialElement.get_Parameter(BuiltInParameter.ROOM_AREA);
            if (param != null)
            {
                dArea = param.AsDouble();
                dArea *= (scale * scale);
            }


            SpatialElementBoundaryOptions options = ExporterIFCUtils.GetSpatialElementBoundaryOptions(exporterIFC, spatialElement);
            IList<CurveLoop> curveLoops = ExporterIFCUtils.GetRoomBoundaryAsCurveLoopArray(spatialElement, options, true);

            IFCLevelInfo levelInfo = exporterIFC.GetLevelInfo(levelId);

            string strSpaceNumber = null;
            string strSpaceName = null;
            string strSpaceDesc = null;

            bool isArea = spatialElement is Area;
            if (!isArea)
            {
                Parameter paramRoomNum = spatialElement.get_Parameter(BuiltInParameter.ROOM_NUMBER);
                if (paramRoomNum != null)
                {
                    strSpaceNumber = paramRoomNum.AsString();
                }

                Parameter paramRoomName = spatialElement.get_Parameter(BuiltInParameter.ROOM_NAME);
                if (paramRoomName != null)
                {
                    strSpaceName = paramRoomName.AsString();
                }

                Parameter paramRoomComm = spatialElement.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
                if (paramRoomComm != null)
                {
                    strSpaceDesc = paramRoomComm.AsString();
                }
            }
            else
            {
                Element level = document.get_Element(levelId);
                if (level != null)
                {
                    strSpaceNumber = level.Name + " GSA Design Gross Area";
                }
            }

            //assign empty string if it is null
            if (strSpaceNumber == null) strSpaceNumber = "";
            if (strSpaceName == null) strSpaceName = "";
            if (strSpaceDesc == null) strSpaceDesc = "";
            IFCLabel name = IFCLabel.Create(strSpaceNumber);
            IFCLabel longName = IFCLabel.Create(strSpaceName);
            IFCLabel desc = IFCLabel.Create(strSpaceDesc);

            IFCFile file = exporterIFC.GetFile();

            IFCAnyHandle localPlacement = setter.GetPlacement();
            ElementType elemType = document.get_Element(spatialElement.GetTypeId()) as ElementType;
            bool isObjectExternal = CategoryUtil.IsElementExternal(spatialElement);
            IFCMeasureValue elevationWithFlooring = IFCMeasureValue.Create();

            double roomHeight = 0.0;

            roomHeight = GetHeight(spatialElement, scale, levelInfo);

            double bottomOffset = 0.0;
            Parameter paramBottomOffset = spatialElement.get_Parameter(BuiltInParameter.ROOM_LOWER_OFFSET);
            bottomOffset = paramBottomOffset != null ? paramBottomOffset.AsDouble() : 0.0;

            XYZ zDir = new XYZ(0, 0, 1);
            XYZ orig = new XYZ(0, 0, levelInfo.Elevation + bottomOffset);

            Plane plane = new Plane(zDir, orig); // room calculated as level offset.

            GeometryElement geomElem = null;
            if (spatialElement is Autodesk.Revit.DB.Architecture.Room)
            {
                Autodesk.Revit.DB.Architecture.Room room = spatialElement as Autodesk.Revit.DB.Architecture.Room;
                geomElem = room.ClosedShell;
            }
            else if (spatialElement is Autodesk.Revit.DB.Mechanical.Space)
            {
                Autodesk.Revit.DB.Mechanical.Space space = spatialElement as Autodesk.Revit.DB.Mechanical.Space;
                geomElem = space.ClosedShell;
            }

            IFCAnyHandle spaceHnd = null;
            IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData();
            extraParams.SetLocalPlacement(localPlacement);
            extraParams.PossibleExtrusionAxes = IFCExtrusionAxes.TryZ;

            using (IFCTransaction tr2 = new IFCTransaction(file))
            {
                IFCAnyHandle repHnd = null;
                if (!(exporterIFC.ExportAs2x2 || Use2DRoomBoundaryForRoomVolumeCalculation()) && geomElem != null)
                {

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

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

                    IList<GeometryObject> geomObjects = new List<GeometryObject>();

                    foreach (Solid solid in solids)
                        geomObjects.Add(solid);

                    IFCAnyHandle shapeRep = BodyExporter.ExportBody(spatialElement.Document.Application, exporterIFC, catId, geomObjects, tryToExportAsExtrusion, extraParams);
                    IList<IFCAnyHandle> shapeReps = new List<IFCAnyHandle>();
                    shapeReps.Add(shapeRep);
                    repHnd = file.CreateProductDefinitionShape(IFCLabel.Create(), IFCLabel.Create(), shapeReps);
                }
                else
                {
                    IFCAnyHandle shapeRep = file.CreateExtrudedSolidFromCurveLoop(exporterIFC, catId, curveLoops, plane, zDir, roomHeight); //pScaledOrig?
                    HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
                    bodyItems.Add(shapeRep);
                    shapeRep = RepresentationUtil.CreateSweptSolidRep(exporterIFC, catId, exporterIFC.Get3DContextHandle(), bodyItems, IFCAnyHandle.Create());
                    IList<IFCAnyHandle> shapeReps = new List<IFCAnyHandle>();
                    shapeReps.Add(shapeRep);
                    repHnd = file.CreateProductDefinitionShape(IFCLabel.Create(), IFCLabel.Create(), shapeReps);
                }

                extraParams.ScaledHeight = roomHeight;
                extraParams.ScaledArea = dArea;

                spaceHnd = file.CreateSpace(IFCLabel.CreateGUID(spatialElement),
                                                  exporterIFC.GetOwnerHistoryHandle(),
                                                  NamingUtil.GetNameOverride(spatialElement, name),
                                                  NamingUtil.GetDescriptionOverride(spatialElement, desc),
                                                  NamingUtil.GetObjectTypeOverride(spatialElement, IFCLabel.Create()),
                                                  extraParams.GetLocalPlacement(), repHnd, longName, IFCElementComposition.Element
                                                  , isObjectExternal, elevationWithFlooring);
                tr2.Commit();
            }

            productWrapper.AddSpace(spaceHnd, levelInfo, extraParams, true);

            // Save room handle for later use/relationships
            exporterIFC.RegisterSpatialElementHandle(spatialElement.Id, spaceHnd);

            if (!MathUtil.IsAlmostZero(dArea) && !(exporterIFC.FileVersion == IFCVersion.IFCCOBIE))
            {
                ExporterIFCUtils.CreatePreCOBIEGSAQuantities(exporterIFC, spaceHnd, "GSA Space Areas", (isArea ? "GSA Design Gross Area" : "GSA BIM Area"), dArea);
            }

            // Export BaseQuantities for RoomElem
            if (exporterIFC.ExportBaseQuantities && !(exporterIFC.FileVersion == IFCVersion.IFCCOBIE))
            {
                ExporterIFCUtils.CreateNonCOBIERoomQuantities(exporterIFC, spaceHnd, spatialElement, dArea, roomHeight);
            }
        }
Пример #24
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="rampHnd">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="placementSetter">The placement setter.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportMultistoryRamp(ExporterIFC exporterIFC, Element ramp, int numFlights,
                                                IFCAnyHandle rampHnd, IList <IFCAnyHandle> components, IList <IFCExtrusionCreationData> componentECData,
                                                IFCPlacementSetter placementSetter, ProductWrapper productWrapper)
        {
            if (numFlights < 2)
            {
                return;
            }

            double scale = exporterIFC.LinearScale;

            double heightNonScaled = GetRampHeight(exporterIFC, ramp);

            if (heightNonScaled < MathUtil.Eps())
            {
                return;
            }

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

            IFCAnyHandle localPlacement = IFCAnyHandleUtil.GetObjectPlacement(rampHnd);

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

            IList <IFCAnyHandle> rampLocalPlacementHnds = 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);
                rampLocalPlacementHnds.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;
            ElementId catId   = CategoryUtil.GetSafeCategoryId(ramp);

            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.GetObjectPlacement(component);
                IFCAnyHandle localRelativePlacement =
                    (localLocalPlacement == null) ? null : IFCAnyHandleUtil.GetInstanceAttribute(localLocalPlacement, "RelativePlacement");

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

                IList <IFCAnyHandle> localComponentHnds = new List <IFCAnyHandle>();
                if (isSubRamp)
                {
                    string      componentType = IFCAnyHandleUtil.GetEnumerationAttribute(component, "ShapeType");
                    IFCRampType localRampType = GetIFCRampType(componentType);

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

                        localComponentHnds.Add(IFCInstanceExporter.CreateRamp(file, GUIDUtil.CreateGUID(), ownerHistory,
                                                                              localComponentNames[ii], componentDescription, componentObjectType, componentPlacementHnds[ii], representationCopy,
                                                                              componentElementTag, localRampType));
                    }
                }
                else if (IFCAnyHandleUtil.IsSubTypeOf(component, IFCEntityType.IfcRampFlight))
                {
                    for (int ii = 0; ii < numFlights - 1; ii++)
                    {
                        IFCAnyHandle representationCopy =
                            ExporterUtil.CopyProductDefinitionShape(exporterIFC, ramp, catId, componentProdRep);

                        localComponentHnds.Add(IFCInstanceExporter.CreateRampFlight(file, GUIDUtil.CreateGUID(), ownerHistory,
                                                                                    localComponentNames[ii], componentDescription, componentObjectType, componentPlacementHnds[ii], representationCopy,
                                                                                    componentElementTag));
                    }
                }
                else if (IFCAnyHandleUtil.IsSubTypeOf(component, IFCEntityType.IfcSlab))
                {
                    string      componentType    = IFCAnyHandleUtil.GetEnumerationAttribute(component, "PredefinedType");
                    IFCSlabType localLandingType = FloorExporter.GetIFCSlabType(componentType);

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

                        localComponentHnds.Add(IFCInstanceExporter.CreateSlab(file, GUIDUtil.CreateGUID(), ownerHistory,
                                                                              localComponentNames[ii], componentDescription, componentObjectType, componentPlacementHnds[ii], representationCopy,
                                                                              componentElementTag, localLandingType));
                    }
                }
                else if (IFCAnyHandleUtil.IsSubTypeOf(component, IFCEntityType.IfcMember))
                {
                    for (int ii = 0; ii < numFlights - 1; ii++)
                    {
                        IFCAnyHandle representationCopy =
                            ExporterUtil.CopyProductDefinitionShape(exporterIFC, ramp, catId, componentProdRep);

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

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

            // finally add a copy of the container.
            IList <IFCAnyHandle> rampCopyHnds = new List <IFCAnyHandle>();

            for (int ii = 0; ii < numFlights - 1; ii++)
            {
                string      rampName         = IFCAnyHandleUtil.GetStringAttribute(rampHnd, "Name");
                string      rampObjectType   = IFCAnyHandleUtil.GetStringAttribute(rampHnd, "ObjectType");
                string      rampDescription  = IFCAnyHandleUtil.GetStringAttribute(rampHnd, "Description");
                string      rampElementTag   = IFCAnyHandleUtil.GetStringAttribute(rampHnd, "Tag");
                string      rampTypeAsString = IFCAnyHandleUtil.GetEnumerationAttribute(rampHnd, "ShapeType");
                IFCRampType rampType         = GetIFCRampType(rampTypeAsString);

                string containerRampName = rampName + ":" + (ii + 2);
                rampCopyHnds.Add(IFCInstanceExporter.CreateRamp(file, GUIDUtil.CreateGUID(), ownerHistory,
                                                                containerRampName, rampDescription, rampObjectType, rampLocalPlacementHnds[ii], null, rampElementTag, rampType));

                productWrapper.AddElement(ramp, rampCopyHnds[ii], levelInfos[ii], null, true);
            }

            for (int ii = 0; ii < numFlights - 1; ii++)
            {
                StairRampContainerInfo stairRampInfo = new StairRampContainerInfo(rampCopyHnds[ii], newComponents[ii],
                                                                                  rampLocalPlacementHnds[ii]);
                ExporterCacheManager.StairRampContainerInfoCache.AppendStairRampContainerInfo(ramp.Id, stairRampInfo);
            }
        }
Пример #25
0
        /// <summary>
        /// Exports a floor to IFC slab.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="floor">
        /// The floor element.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="ifcEnumType">
        /// The string value represents the IFC type.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        /// <param name="exportParts">
        /// Whether to export parts or not.
        /// </param>
        /// <returns>
        /// True if the floor is exported successfully, false otherwise.
        /// </returns>
        public static void ExportFloor(ExporterIFC exporterIFC, Element floorElement, GeometryElement geometryElement, string ifcEnumType,
                                       ProductWrapper productWrapper, bool exportParts)
        {
            if (geometryElement == null)
            {
                return;
            }

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

                        int numReps = exportParts ? 1 : prodReps.Count;

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

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

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

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

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

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

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

                            slabHnds.Add(slabHnd);

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

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

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

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

                return;
            }
        }
Пример #26
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 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;
        }
        /// <summary>
        /// Exports curtain object as one Brep.
        /// </summary>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="wallElement">
        /// The curtain wall element.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter object.
        /// </param>
        /// <param name="localPlacement">
        /// The local placement handle.
        /// </param>
        /// <returns>
        /// The handle.
        /// </returns>
        public static IFCAnyHandle ExportCurtainObjectCommonAsOneBRep(ElementSet allSubElements, Element wallElement,
           ExporterIFC exporterIFC, IFCPlacementSetter setter, IFCAnyHandle localPlacement)
        {
            IFCAnyHandle prodDefRep = IFCAnyHandle.Create();
            double eps = wallElement.Document.Application.VertexTolerance * exporterIFC.LinearScale;

            IFCFile file = exporterIFC.GetFile();
            IFCAnyHandle contextOfItems = exporterIFC.Get3DContextHandle();

            IFCGeometryInfo info = IFCGeometryInfo.CreateSurfaceGeometryInfo(eps);

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

            // Want to make sure we don't accidentally add a mullion or curtain line more than once.
            HashSet<ElementId> alreadyVisited = new HashSet<ElementId>();

            Options geomOptions = new Options();
            foreach (Element subElem in allSubElements)
            {
                GeometryElement geometryElement = subElem.get_Geometry(geomOptions);
                if (geometryElement == null)
                    continue;

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

                ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false);
                IFCAnyHandle outer = file.CreateClosedShell(info.GetSurfaces());

                if (outer.HasValue)
                    bodyItems.Add(RepresentationUtil.CreateFacetedBRep(exporterIFC, outer));
            }

            if (bodyItems.Count == 0)
                return prodDefRep;

            ElementId catId = CategoryUtil.GetSafeCategoryId(wallElement);
            IFCAnyHandle shapeRep = RepresentationUtil.CreateBRepRep(exporterIFC, catId, contextOfItems, bodyItems);
            if (!shapeRep.HasValue)
                return prodDefRep;

            IList<IFCAnyHandle> shapeReps = new List<IFCAnyHandle>();
            shapeReps.Add(shapeRep);
            prodDefRep = file.CreateProductDefinitionShape(IFCLabel.Create(), IFCLabel.Create(), shapeReps);
            return prodDefRep;
        }
Пример #29
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();
            }
        }
Пример #30
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="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>
        public static void CreateOpeningsIfNecessary(IFCAnyHandle elementHandle, Element element, IFCExtrusionCreationData extraParams,
           ExporterIFC exporterIFC, IFCAnyHandle originalPlacement,
           IFCPlacementSetter setter, IFCProductWrapper wrapper)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(elementHandle))
                return;

            ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

            IList<IFCExtrusionData> info = extraParams.GetOpenings();
            CreateOpeningsIfNecessaryBase(elementHandle, element, info, extraParams, exporterIFC, originalPlacement, setter, wrapper);
            extraParams.ClearOpenings();
        }
Пример #31
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="rampHnd">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="placementSetter">The placement setter.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportMultistoryRamp(ExporterIFC exporterIFC, Element ramp, int numFlights,
            IFCAnyHandle rampHnd, IList<IFCAnyHandle> components, IList<IFCExtrusionCreationData> componentECData,
            IFCPlacementSetter placementSetter, ProductWrapper productWrapper)
        {
            if (numFlights < 2)
                return;

            double scale = exporterIFC.LinearScale;

            double heightNonScaled = GetRampHeight(exporterIFC, ramp);
            if (heightNonScaled < MathUtil.Eps())
                return;

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(rampHnd))
                return;

            IFCAnyHandle localPlacement = IFCAnyHandleUtil.GetObjectPlacement(rampHnd);
            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);

            IList<IFCAnyHandle> rampLocalPlacementHnds = 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);
                rampLocalPlacementHnds.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;
            ElementId catId = CategoryUtil.GetSafeCategoryId(ramp);

            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.GetObjectPlacement(component);
                IFCAnyHandle localRelativePlacement =
                    (localLocalPlacement == null) ? null : IFCAnyHandleUtil.GetInstanceAttribute(localLocalPlacement, "RelativePlacement");

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

                IList<IFCAnyHandle> localComponentHnds = new List<IFCAnyHandle>();
                if (isSubRamp)
                {
                    string componentType = IFCAnyHandleUtil.GetEnumerationAttribute(component, "ShapeType");
                    IFCRampType localRampType = GetIFCRampType(componentType);

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

                        localComponentHnds.Add(IFCInstanceExporter.CreateRamp(file, GUIDUtil.CreateGUID(), ownerHistory,
                            localComponentNames[ii], componentDescription, componentObjectType, componentPlacementHnds[ii], representationCopy,
                            componentElementTag, localRampType));
                    }
                }
                else if (IFCAnyHandleUtil.IsSubTypeOf(component, IFCEntityType.IfcRampFlight))
                {
                    for (int ii = 0; ii < numFlights - 1; ii++)
                    {
                        IFCAnyHandle representationCopy =
                            ExporterUtil.CopyProductDefinitionShape(exporterIFC, ramp, catId, componentProdRep);

                        localComponentHnds.Add(IFCInstanceExporter.CreateRampFlight(file, GUIDUtil.CreateGUID(), ownerHistory,
                            localComponentNames[ii], componentDescription, componentObjectType, componentPlacementHnds[ii], representationCopy,
                            componentElementTag));
                    }
                }
                else if (IFCAnyHandleUtil.IsSubTypeOf(component, IFCEntityType.IfcSlab))
                {
                    string componentType = IFCAnyHandleUtil.GetEnumerationAttribute(component, "PredefinedType");
                    IFCSlabType localLandingType = FloorExporter.GetIFCSlabType(componentType);

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

                        localComponentHnds.Add(IFCInstanceExporter.CreateSlab(file, GUIDUtil.CreateGUID(), ownerHistory,
                            localComponentNames[ii], componentDescription, componentObjectType, componentPlacementHnds[ii], representationCopy,
                            componentElementTag, localLandingType));
                    }
                }
                else if (IFCAnyHandleUtil.IsSubTypeOf(component, IFCEntityType.IfcMember))
                {
                    for (int ii = 0; ii < numFlights - 1; ii++)
                    {
                        IFCAnyHandle representationCopy =
                            ExporterUtil.CopyProductDefinitionShape(exporterIFC, ramp, catId, componentProdRep);

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

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

            // finally add a copy of the container.
            IList<IFCAnyHandle> rampCopyHnds = new List<IFCAnyHandle>();
            for (int ii = 0; ii < numFlights - 1; ii++)
            {
                string rampName = IFCAnyHandleUtil.GetStringAttribute(rampHnd, "Name");
                string rampObjectType = IFCAnyHandleUtil.GetStringAttribute(rampHnd, "ObjectType");
                string rampDescription = IFCAnyHandleUtil.GetStringAttribute(rampHnd, "Description");
                string rampElementTag = IFCAnyHandleUtil.GetStringAttribute(rampHnd, "Tag");
                string rampTypeAsString = IFCAnyHandleUtil.GetEnumerationAttribute(rampHnd, "ShapeType");
                IFCRampType rampType = GetIFCRampType(rampTypeAsString);

                string containerRampName = rampName + ":" + (ii + 2);
                rampCopyHnds.Add(IFCInstanceExporter.CreateRamp(file, GUIDUtil.CreateGUID(), ownerHistory,
                    containerRampName, rampDescription, rampObjectType, rampLocalPlacementHnds[ii], null, rampElementTag, rampType));

                productWrapper.AddElement(ramp, rampCopyHnds[ii], levelInfos[ii], null, true);
            }

            for (int ii = 0; ii < numFlights - 1; ii++)
            {
                StairRampContainerInfo stairRampInfo = new StairRampContainerInfo(rampCopyHnds[ii], newComponents[ii],
                    rampLocalPlacementHnds[ii]);
                ExporterCacheManager.StairRampContainerInfoCache.AppendStairRampContainerInfo(ramp.Id, stairRampInfo);
            }
        }
        /// <summary>
        /// Exports curtain object as container.
        /// </summary>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="wallElement">
        /// The curtain wall element.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void ExportCurtainObjectCommonAsContainer(ICollection<ElementId> allSubElements, Element wallElement,
           ExporterIFC exporterIFC, ProductWrapper origWrapper, IFCPlacementSetter currSetter)
        {
            if (wallElement == null)
                return;

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

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

                        try
                        {
                            if (subElem is FamilyInstance)
                            {
                                if (subElem is Mullion)
                                {
                                    if (exporterIFC.ExportAs2x2)
                                        ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper);
                                    else
                                    {
                                        IFCAnyHandle currLocalPlacement = currSetter.GetPlacement();
                                        using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                                        {
                                            MullionExporter.Export(exporterIFC, subElem as Mullion, geomElem, currLocalPlacement, extraParams, currSetter,
                                                productWrapper);
                                        }
                                    }
                                }
                                else
                                {
                                    FamilyInstance subFamInst = subElem as FamilyInstance;

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

                                    if (exporterIFC.ExportAs2x2)
                                    {
                                        if ((exportType == IFCExportType.DontExport) || (exportType == IFCExportType.ExportPlateType) ||
                                           (exportType == IFCExportType.ExportMemberType))
                                            exportType = IFCExportType.ExportBuildingElementProxy;
                                    }
                                    else
                                    {
                                        if (exportType == IFCExportType.DontExport)
                                        {
                                            ifcEnumType = "CURTAIN_PANEL";
                                            exportType = IFCExportType.ExportPlateType;
                                        }
                                    }

                                    IFCAnyHandle currLocalPlacement = currSetter.GetPlacement();
                                    using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                                    {
                                        FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem(exporterIFC, subFamInst, exportType, ifcEnumType, productWrapper,
                                            ElementId.InvalidElementId, null, currLocalPlacement);
                                    }
                                }
                            }
                            else if (subElem is CurtainGridLine)
                            {
                                ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper);
                            }
                        }
                        catch (Exception ex)
                        {
                            if (ExporterUtil.IsFatalException(wallElement.Document, ex))
                                throw ex;
                            continue;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Exports a generic family instance as IFC instance.
        /// </summary>
        /// <param name="type">The export type.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="familyInstance">The element.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        /// <param name="setter">The 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,
           ProductWrapper wrapper, IFCPlacementSetter setter, IFCExtrusionCreationData extraParams,
           string instanceGUID, IFCAnyHandle ownerHistory,
           string instanceName, string instanceDescription, string instanceObjectType,
           IFCAnyHandle productRepresentation,
           string instanceTag, IFCAnyHandle overrideLocalPlacement)
        {
            IFCFile file = exporterIFC.GetFile();
            Document doc = familyInstance.Document;

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

            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, instanceTag);
                        break;
                    }
                case IFCExportType.ExportMemberType:
                    {
                        instanceHandle = IFCInstanceExporter.CreateMember(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        break;
                    }
                case IFCExportType.ExportPlateType:
                    {
                        IFCAnyHandle localPlacement = localPlacementToUse;
                        if (overrideLocalPlacement!= null)
                        {
                            isChildInContainer = true;
                            localPlacement = overrideLocalPlacement;
                        }

                        instanceHandle = IFCInstanceExporter.CreatePlate(file, instanceGUID, ownerHistory,
                            instanceName, instanceDescription, instanceObjectType, localPlacement, productRepresentation, instanceTag);
                        break;
                    }
                case IFCExportType.ExportDistributionControlElement:
                    {
                        instanceHandle = IFCInstanceExporter.CreateDistributionControlElement(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                           null);
                        break;
                    }
                case IFCExportType.ExportDistributionElement:
                    {
                        instanceHandle = IFCInstanceExporter.CreateDistributionElement(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        break;
                    }
                case IFCExportType.ExportFastenerType:
                    {
                        instanceHandle = IFCInstanceExporter.CreateFastener(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        break;
                    }
                case IFCExportType.ExportMechanicalFastenerType:
                    {
                        double? nominalDiameter = null;
                        double? nominalLength = null;

                        double nominalDiameterVal, nominalLengthVal;
                        if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalDiameter", out nominalDiameterVal))
                            nominalDiameter = nominalDiameterVal;
                        if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalLength", out nominalLengthVal))
                            nominalLength = nominalLengthVal;

                        instanceHandle = IFCInstanceExporter.CreateMechanicalFastener(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                           nominalDiameter, nominalLength);
                        break;
                    }
                default:
                    {
                        if ((type == IFCExportType.ExportFurnishingElement) || IsFurnishingElementSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFurnishingElement(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportEnergyConversionDevice) || IsEnergyConversionDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateEnergyConversionDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowFitting) || IsFlowFittingSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowFitting(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowMovingDevice) || IsFlowMovingDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowMovingDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowSegment) || IsFlowSegmentSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowSegment(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowStorageDevice) || IsFlowStorageDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowStorageDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowTerminal) || IsFlowTerminalSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowTerminal(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowTreatmentDevice) || IsFlowTreatmentDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowTreatmentDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowController) || IsFlowControllerSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowController(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportDistributionFlowElement) || IsDistributionFlowElementSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateDistributionFlowElement(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        break;
                    }
            }

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle))
            {
                if (roomId == ElementId.InvalidElementId)
                {
                    wrapper.AddElement(instanceHandle, setter, extraParams, !isChildInContainer);
                }
                else
                {
                    exporterIFC.RelateSpatialElement(roomId, instanceHandle);
                    wrapper.AddElement(instanceHandle, setter, extraParams, false);
                }
            }
            return instanceHandle;
        }
Пример #34
0
        /// <summary>
        /// Exports text note elements.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="textNote">
        /// The text note element.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, TextNote textNote, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                string textString = textNote.Text;
                if (String.IsNullOrEmpty(textString))
                {
                    throw new Exception("TextNote does not have test string.");
                }

                ElementId symId = textNote.GetTypeId();
                if (symId == ElementId.InvalidElementId)
                {
                    throw new Exception("TextNote does not have valid type id.");
                }

                PresentationStyleAssignmentCache cache = ExporterCacheManager.PresentationStyleAssignmentCache;
                IFCAnyHandle presHnd = cache.Find(symId);
                if (IFCAnyHandleUtil.IsNullOrHasNoValue(presHnd))
                {
                    TextElementType textElemType = textNote.Symbol;
                    CreatePresentationStyleAssignmentForTextElementType(exporterIFC, textElemType, cache);
                    presHnd = cache.Find(symId);
                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(presHnd))
                    {
                        throw new Exception("Failed to create presentation style assignment for TextElementType.");
                    }
                }

                HashSet <IFCAnyHandle> presHndSet = new HashSet <IFCAnyHandle>();
                presHndSet.Add(presHnd);

                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, textNote))
                {
                    double       linScale  = exporterIFC.LinearScale;
                    const double planScale = 100.0;  // currently hardwired.

                    XYZ orig = textNote.Coord;
                    orig = orig.Multiply(linScale);
                    XYZ yDir = textNote.UpDirection;
                    XYZ xDir = textNote.BaseDirection;
                    XYZ zDir = xDir.CrossProduct(yDir);

                    double sizeX = textNote.LineWidth * linScale * planScale;
                    double sizeY = textNote.Height * linScale * planScale;

                    // When we display text on screen, we "flip" it if the xDir is negative with relation to
                    // the X-axis.  So if it is, we'll flip x and y.
                    bool flipOrig = false;
                    if (xDir.X < 0)
                    {
                        xDir     = xDir.Multiply(-1.0);
                        yDir     = yDir.Multiply(-1.0);
                        flipOrig = true;
                    }

                    // xFactor, yFactor only used if flipOrig.
                    double xFactor = 0.0, yFactor = 0.0;
                    string boxAlignment = ConvertTextNoteAlignToBoxAlign(textNote, out xFactor, out yFactor);

                    // modify the origin to match the alignment.  In Revit, the origin is at the top-left (unless flipped,
                    // then bottom-right).
                    if (flipOrig)
                    {
                        orig = orig.Add(xDir.Multiply(sizeX * xFactor));
                        orig = orig.Add(yDir.Multiply(sizeY * yFactor));
                    }

                    IFCAnyHandle origin = ExporterUtil.CreateAxis(file, orig, zDir, xDir);

                    IFCAnyHandle extent         = IFCInstanceExporter.CreatePlanarExtent(file, sizeX, sizeY);
                    IFCAnyHandle repItemHnd     = IFCInstanceExporter.CreateTextLiteralWithExtent(file, textString, origin, Toolkit.IFCTextPath.Left, extent, boxAlignment);
                    IFCAnyHandle annoTextOccHnd = IFCInstanceExporter.CreateStyledItem(file, repItemHnd, presHndSet, null);

                    ElementId catId = textNote.Category != null ? textNote.Category.Id : ElementId.InvalidElementId;
                    HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>();
                    bodyItems.Add(repItemHnd);
                    IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateAnnotationSetRep(exporterIFC, textNote, catId, exporterIFC.Get2DContextHandle(), bodyItems);

                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd))
                    {
                        throw new Exception("Failed to create shape representation.");
                    }

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

                    IFCAnyHandle prodShapeHnd = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                    IFCAnyHandle annoHnd      = IFCInstanceExporter.CreateAnnotation(file, ExporterIFCUtils.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                                                                     null, null, null, setter.GetPlacement(), prodShapeHnd);

                    productWrapper.AddAnnotation(annoHnd, setter.GetLevelInfo(), true);
                }

                tr.Commit();
            }
        }
Пример #35
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();
                    }
                }
            }
        }
Пример #36
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 ProductWrapper.
        /// </param>
        public static void ExportFooting(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement,
                                         string ifcEnumType, ProductWrapper 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, null, null, ExporterUtil.GetBaseLevelIdForElement(element)))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(setter.GetPlacement());

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


                            matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, exporterIFC, element);
                            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                            prodRep = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC,
                                                                                                 element, catId, geometryElement, bodyExporterOptions, null, ecData, true);
                            if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodRep))
                            {
                                ecData.ClearOpenings();
                                return;
                            }
                        }

                        string instanceGUID                = GUIDUtil.CreateGUID(element);
                        string instanceName                = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                        string instanceDescription         = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceObjectType          = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                        string instanceTag                 = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));
                        Toolkit.IFCFootingType footingType = GetIFCFootingType(element, ifcEnumType);

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

                        if (exportParts)
                        {
                            PartExporter.ExportHostPart(exporterIFC, element, footing, productWrapper, setter, setter.GetPlacement(), null);
                        }
                        else
                        {
                            if (matId != ElementId.InvalidElementId)
                            {
                                CategoryUtil.CreateMaterialAssociation(exporterIFC, footing, matId);
                            }
                        }

                        productWrapper.AddElement(element, footing, setter, ecData, true);

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

                tr.Commit();
            }
        }
Пример #37
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 ProductWrapper.</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, ProductWrapper 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, GUIDUtil.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, GUIDUtil.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);
            }
        }
Пример #38
0
 /// <summary>
 /// Add a generic element to the wrapper, with associated setter and extrusion data information.
 /// </summary>
 /// <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(IFCAnyHandle handle, IFCPlacementSetter setter, IFCExtrusionCreationData data, bool relateToLevel)
 {
     m_InternalWrapper.AddElement(handle, setter, data, relateToLevel);
 }
Пример #39
0
        /// <summary>
        /// Exports a curve element to IFC curve annotation.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="curveElement">
        /// The curve element to be exported.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportCurveElement(ExporterIFC exporterIFC, CurveElement curveElement, GeometryElement geometryElement,
                                              IFCProductWrapper productWrapper)
        {
            if (geometryElement == null || !ShouldCurveElementBeExported(curveElement))
            {
                return;
            }

            SketchPlane sketchPlane = curveElement.SketchPlane;

            if (sketchPlane == null)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

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

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

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

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

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

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

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

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

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

                        annotationCache.AddAnnotation(sketchPlane.Id, curveStyle, curveAnno);
                    }
                }
                transaction.Commit();
            }
        }
Пример #40
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 ProductWrapper.
        /// </param>
        public static void ExportBeam(ExporterIFC exporterIFC,
                                      Element element, GeometryElement geometryElement, ProductWrapper 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, ExporterUtil.GetBaseLevelIdForElement(element)))
                {
                    IFCAnyHandle          localPlacement = setter.GetPlacement();
                    SolidMeshGeometryInfo solidMeshInfo  = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement);

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

                        // There may be an offset to make the local coordinate system
                        // be near the origin.  This offset will be used to move the axis to the new LCS.
                        Transform offsetTransform = 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)))
                        {
                            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))
                            {
                                // This is used by the BeamSlopeCalculator.  This should probably be generated automatically by
                                // CreateExtrusionWithClipping.
                                IFCExtrusionBasis bestAxis = (Math.Abs(beamDirection[0]) > Math.Abs(beamDirection[1])) ?
                                                             IFCExtrusionBasis.BasisX : IFCExtrusionBasis.BasisY;
                                extrusionCreationData.Slope = GeometryUtil.GetSimpleExtrusionSlope(beamDirection, bestAxis);
                                ElementId materialId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(solids[0], exporterIFC, element);
                                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(exporterIFC, element, catId, ElementId.InvalidElementId,
                                                                   solids, meshes, bodyExporterOptions, extrusionCreationData);
                            }
                            else
                            {
                                IList <GeometryObject> geomlist = new List <GeometryObject>();
                                geomlist.Add(geometryElement);
                                bodyData = BodyExporter.ExportBody(exporterIFC, element, catId, ElementId.InvalidElementId,
                                                                   geomlist, bodyExporterOptions, extrusionCreationData);
                            }
                            repHnd          = bodyData.RepresentationHnd;
                            materialIds     = bodyData.MaterialIds;
                            offsetTransform = bodyData.OffsetTransform;
                        }

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

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

                        if (canExportAxis)
                        {
                            XYZ curveOffset = new XYZ(0, 0, 0);
                            if (offsetTransform != null)
                            {
                                curveOffset = -offsetTransform.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);

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

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

                        string instanceGUID        = GUIDUtil.CreateGUID(element);
                        string instanceName        = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                        string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceObjectType  = NamingUtil.GetObjectTypeOverride(element, NamingUtil.CreateIFCObjectName(exporterIFC, element));
                        string instanceTag         = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));

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

                        productWrapper.AddElement(element, beam, setter, extrusionCreationData, true);

                        OpeningUtil.CreateOpeningsIfNecessary(beam, element, extrusionCreationData, offsetTransform, 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(exporterIFC, beam, materialIds);
                        }

                        // Register the beam's IFC handle for later use by truss and beam system export.
                        ExporterCacheManager.ElementToHandleCache.Register(element.Id, beam);
                    }
                }

                transaction.Commit();
            }
        }
Пример #41
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);
            }
        }
Пример #42
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 ProductWrapper.</param>
        public static void ExportRamp(ExporterIFC exporterIFC, string ifcEnumType, Element ramp, GeometryElement geometryElement,
                                      int numFlights, ProductWrapper productWrapper)
        {
            if (ramp == null || geometryElement == null)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

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

                        GeometryElement rampGeom = GeometryUtil.GetOneLevelGeometryElement(geometryElement);

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

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions();
                        IFCAnyHandle        representation      = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC,
                                                                                                                             ramp, categoryId, rampGeom, bodyExporterOptions, null, ecData, out bodyData);

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

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

                        List <IFCAnyHandle> components = new List <IFCAnyHandle>();
                        IList <IFCExtrusionCreationData> componentExtrusionData = new List <IFCExtrusionCreationData>();
                        IFCAnyHandle containedRampHnd = IFCInstanceExporter.CreateRamp(file, containedRampGuid, ownerHistory, rampName,
                                                                                       rampDescription, rampObjectType, containedRampLocalPlacement, representation, elementTag, rampType);
                        components.Add(containedRampHnd);
                        componentExtrusionData.Add(ecData);
                        //productWrapper.AddElement(containedRampHnd, placementSetter.LevelInfo, ecData, false);
                        CategoryUtil.CreateMaterialAssociations(exporterIFC, containedRampHnd, bodyData.MaterialIds);

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

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

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

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

                        ExportMultistoryRamp(exporterIFC, ramp, numFlights, rampHnd, components, componentExtrusionData, placementSetter,
                                             productWrapper);
                    }
                    tr.Commit();
                }
            }
        }
        /// <summary>
        ///  Creates a new IfcAnnotation object.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="curveElement">The curve element.</param>
        /// <param name="categoryId">The category id.</param>
        /// <param name="sketchPlaneId">The sketch plane id.</param>
        /// <param name="refPlane">The reference plane.</param>
        /// <param name="curveStyle">The curve style.</param>
        /// <param name="placementSetter">The placemenet setter.</param>
        /// <param name="localPlacement">The local placement.</param>
        /// <param name="repItemHnd">The representation item.</param>
        /// <returns>The handle.</returns>
        static IFCAnyHandle CreateCurveAnnotation(ExporterIFC exporterIFC, Element curveElement, ElementId categoryId, ElementId sketchPlaneId,
            Plane refPlane, IFCAnyHandle curveStyle, IFCPlacementSetter placementSetter, IFCAnyHandle localPlacement, IFCAnyHandle repItemHnd)
        {
            HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
            bodyItems.Add(repItemHnd);
            IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateAnnotationSetRep(exporterIFC, curveElement, categoryId, exporterIFC.Get2DContextHandle(), bodyItems);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd))
                throw new Exception("Failed to create shape representation.");

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

            IFCFile file = exporterIFC.GetFile();
            IFCAnyHandle prodShapeHnd = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapes);

            XYZ xDir = refPlane.XVec; XYZ zDir = refPlane.Normal; XYZ origin = refPlane.Origin;

            // subtract out level origin if we didn't already before.
            IFCLevelInfo levelInfo = placementSetter.GetLevelInfo();
            if (levelInfo != null && !MathUtil.IsAlmostEqual(zDir.Z, 1.0))
            {
                zDir -= new XYZ(0, 0, levelInfo.Elevation);
            }

            origin = origin * exporterIFC.LinearScale;
            IFCAnyHandle relativePlacement = ExporterUtil.CreateAxis(file, origin, zDir, xDir);
            GeometryUtil.SetRelativePlacement(localPlacement, relativePlacement);

            IFCAnyHandle annotation = IFCInstanceExporter.CreateAnnotation(file, GUIDUtil.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                null, null, null, localPlacement, prodShapeHnd);

            return annotation;
        }
        /// <summary>
        /// Gets the offset of the space boundary.
        /// </summary>
        /// <param name="setter">The placement settter.</param>
        /// <returns>The offset.</returns>
        static XYZ GetSapceBoundaryOffset(IFCPlacementSetter setter)
        {
            IFCAnyHandle localPlacement = setter.GetPlacement();
            double zOffset = setter.Offset;

            IFCAnyHandle relPlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);
            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(relPlacement))
            {
                IFCAnyHandle ptHnd = IFCAnyHandleUtil.GetLocation(relPlacement);
                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(ptHnd))
                {
                    IList<double> addToCoords = IFCAnyHandleUtil.GetCoordinates(ptHnd);
                    return new XYZ(addToCoords[0], addToCoords[1], addToCoords[2] + zOffset);
                }
            }

            return new XYZ(0, 0, zOffset);
        }
Пример #45
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="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>
        public static void CreateOpeningsIfNecessary(IFCAnyHandle elementHandle, Element element, IList<IFCExtrusionData> info,
           ExporterIFC exporterIFC, IFCAnyHandle originalPlacement,
           IFCPlacementSetter setter, IFCProductWrapper wrapper)
        {
            if (!elementHandle.HasValue)
                return;

            IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData();
            CreateOpeningsIfNecessaryBase(elementHandle, element, info, extraParams, exporterIFC, originalPlacement, setter, wrapper);
        }
        /// <summary>
        /// Exports curtain object as one Brep.
        /// </summary>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="wallElement">
        /// The curtain wall element.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter object.
        /// </param>
        /// <param name="localPlacement">
        /// The local placement handle.
        /// </param>
        /// <returns>
        /// The handle.
        /// </returns>
        public static IFCAnyHandle ExportCurtainObjectCommonAsOneBRep(ICollection <ElementId> allSubElements, Element wallElement,
                                                                      ExporterIFC exporterIFC, IFCPlacementSetter setter, IFCAnyHandle localPlacement)
        {
            IFCAnyHandle prodDefRep = null;
            Document     document   = wallElement.Document;
            double       eps        = document.Application.VertexTolerance * exporterIFC.LinearScale;

            IFCFile      file           = exporterIFC.GetFile();
            IFCAnyHandle contextOfItems = exporterIFC.Get3DContextHandle("Body");

            IFCGeometryInfo info = IFCGeometryInfo.CreateFaceGeometryInfo(eps);

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

            // Want to make sure we don't accidentally add a mullion or curtain line more than once.
            HashSet <ElementId> alreadyVisited = new HashSet <ElementId>();

            Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions();

            foreach (ElementId subElemId in allSubElements)
            {
                Element         subElem  = wallElement.Document.GetElement(subElemId);
                GeometryElement geomElem = subElem.get_Geometry(geomOptions);
                if (geomElem == null)
                {
                    continue;
                }

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

                ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geomElem, XYZ.Zero, false);
                HashSet <IFCAnyHandle> faces = new HashSet <IFCAnyHandle>(info.GetSurfaces());
                IFCAnyHandle           outer = IFCInstanceExporter.CreateClosedShell(file, faces);

                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(outer))
                {
                    bodyItems.Add(RepresentationUtil.CreateFacetedBRep(exporterIFC, document, outer, ElementId.InvalidElementId));
                }
            }

            if (bodyItems.Count == 0)
            {
                return(prodDefRep);
            }

            ElementId    catId    = CategoryUtil.GetSafeCategoryId(wallElement);
            IFCAnyHandle shapeRep = RepresentationUtil.CreateBRepRep(exporterIFC, wallElement, catId, contextOfItems, bodyItems);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(shapeRep))
            {
                return(prodDefRep);
            }

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

            shapeReps.Add(shapeRep);

            IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, wallElement.get_Geometry(geomOptions), Transform.Identity);

            if (boundingBoxRep != null)
            {
                shapeReps.Add(boundingBoxRep);
            }

            prodDefRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
            return(prodDefRep);
        }
Пример #47
0
        /// <summary>
        /// Creates IFC room/space/area item, not include boundaries. 
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="spatialElement">
        /// The spatial element.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <returns>
        /// True if created successfully, false otherwise.
        /// </returns>
        static bool CreateIFCSpace(ExporterIFC exporterIFC, SpatialElement spatialElement, IFCProductWrapper productWrapper, IFCPlacementSetter setter)
        {
            IList<CurveLoop> curveLoops = null;
            try
            {
                SpatialElementBoundaryOptions options = ExporterIFCUtils.GetSpatialElementBoundaryOptions(exporterIFC, spatialElement);
                curveLoops = ExporterIFCUtils.GetRoomBoundaryAsCurveLoopArray(spatialElement, options, true);
            }
            catch (Autodesk.Revit.Exceptions.InvalidOperationException)
            {
                //Some spatial elements are not placed that have no boundary loops. Don't export them.
                return false;
            }

            Autodesk.Revit.DB.Document document = spatialElement.Document;
            ElementId levelId = spatialElement.Level != null ? spatialElement.Level.Id : ElementId.InvalidElementId;
            double scale = exporterIFC.LinearScale;

            ElementId catId = spatialElement.Category != null ? spatialElement.Category.Id : ElementId.InvalidElementId;

            double dArea = 0.0;

            Parameter param = spatialElement.get_Parameter(BuiltInParameter.ROOM_AREA);
            if (param != null)
            {
                dArea = param.AsDouble();
                dArea *= (scale * scale);
            }

            IFCLevelInfo levelInfo = exporterIFC.GetLevelInfo(levelId);

            string strSpaceNumber = null;
            string strSpaceName = null;
            string strSpaceDesc = null;

            bool isArea = spatialElement is Area;
            if (!isArea)
            {
                Parameter paramRoomNum = spatialElement.get_Parameter(BuiltInParameter.ROOM_NUMBER);
                if (paramRoomNum != null)
                {
                    strSpaceNumber = paramRoomNum.AsString();
                }

                Parameter paramRoomName = spatialElement.get_Parameter(BuiltInParameter.ROOM_NAME);
                if (paramRoomName != null)
                {
                    strSpaceName = paramRoomName.AsString();
                }

                Parameter paramRoomComm = spatialElement.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
                if (paramRoomComm != null)
                {
                    strSpaceDesc = paramRoomComm.AsString();
                }
            }
            else
            {
                Element level = document.GetElement(levelId);
                if (level != null)
                {
                    strSpaceNumber = level.Name + " GSA Design Gross Area";
                }
            }

            string name = strSpaceNumber;
            string longName = strSpaceName;
            string desc = strSpaceDesc;

            IFCFile file = exporterIFC.GetFile();

            IFCAnyHandle localPlacement = setter.GetPlacement();
            ElementType elemType = document.GetElement(spatialElement.GetTypeId()) as ElementType;
            IFCInternalOrExternal internalOrExternal = CategoryUtil.IsElementExternal(spatialElement) ? IFCInternalOrExternal.External : IFCInternalOrExternal.Internal;

            double roomHeight = 0.0;

            roomHeight = GetHeight(spatialElement, scale, levelId, levelInfo);

            double bottomOffset = 0.0;
            Parameter paramBottomOffset = spatialElement.get_Parameter(BuiltInParameter.ROOM_LOWER_OFFSET);
            bottomOffset = paramBottomOffset != null ? paramBottomOffset.AsDouble() : 0.0;

            XYZ zDir = new XYZ(0, 0, 1);
            XYZ orig = new XYZ(0, 0, levelInfo.Elevation + bottomOffset);

            Plane plane = new Plane(zDir, orig); // room calculated as level offset.

            GeometryElement geomElem = null;
            if (spatialElement is Autodesk.Revit.DB.Architecture.Room)
            {
                Autodesk.Revit.DB.Architecture.Room room = spatialElement as Autodesk.Revit.DB.Architecture.Room;
                geomElem = room.ClosedShell;
            }
            else if (spatialElement is Autodesk.Revit.DB.Mechanical.Space)
            {
                Autodesk.Revit.DB.Mechanical.Space space = spatialElement as Autodesk.Revit.DB.Mechanical.Space;
                geomElem = space.ClosedShell;
            }

            IFCAnyHandle spaceHnd = null;
            using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
            {
                extraParams.SetLocalPlacement(localPlacement);
                extraParams.PossibleExtrusionAxes = IFCExtrusionAxes.TryZ;

                using (IFCTransaction transaction2 = new IFCTransaction(file))
                {
                    IFCAnyHandle repHnd = null;
                    if (!ExporterCacheManager.ExportOptionsCache.Use2DRoomBoundaryForRoomVolumeCreation && geomElem != null)
                    {
                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                        bodyExporterOptions.TessellationLevel = BodyExporterOptions.BodyTessellationLevel.Coarse;
                        repHnd = RepresentationUtil.CreateBRepProductDefinitionShape(spatialElement.Document.Application, exporterIFC, spatialElement,
                            catId, geomElem, bodyExporterOptions, null, extraParams);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd))
                            extraParams.ClearOpenings();
                    }
                    else
                    {
                        IFCAnyHandle shapeRep = ExtrusionExporter.CreateExtrudedSolidFromCurveLoop(exporterIFC, null, curveLoops, plane, zDir, roomHeight);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(shapeRep))
                            return false;
                        IFCAnyHandle styledItemHnd = BodyExporter.CreateSurfaceStyleForRepItem(exporterIFC, document,
                            shapeRep, ElementId.InvalidElementId);

                        HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
                        bodyItems.Add(shapeRep);
                        shapeRep = RepresentationUtil.CreateSweptSolidRep(exporterIFC, spatialElement, catId, exporterIFC.Get3DContextHandle("Body"), bodyItems, null);
                        IList<IFCAnyHandle> shapeReps = new List<IFCAnyHandle>();
                        shapeReps.Add(shapeRep);
                        repHnd = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                    }

                    extraParams.ScaledHeight = roomHeight;
                    extraParams.ScaledArea = dArea;

                    spaceHnd = IFCInstanceExporter.CreateSpace(file, ExporterIFCUtils.CreateGUID(spatialElement),
                                                      exporterIFC.GetOwnerHistoryHandle(),
                                                      NamingUtil.GetNameOverride(spatialElement, name),
                                                      NamingUtil.GetDescriptionOverride(spatialElement, desc),
                                                      NamingUtil.GetObjectTypeOverride(spatialElement, null),
                                                      extraParams.GetLocalPlacement(), repHnd, longName, Toolkit.IFCElementComposition.Element
                                                      , internalOrExternal, null);
                    transaction2.Commit();
                }

                productWrapper.AddSpace(spaceHnd, levelInfo, extraParams, true);
            }

            // Save room handle for later use/relationships
            ExporterCacheManager.SpatialElementHandleCache.Register(spatialElement.Id, spaceHnd);
            exporterIFC.RegisterSpatialElementHandle(spatialElement.Id, spaceHnd);

            if (!MathUtil.IsAlmostZero(dArea) && !(ExporterCacheManager.ExportOptionsCache.FileVersion == IFCVersion.IFCCOBIE))
            {
                ExporterIFCUtils.CreatePreCOBIEGSAQuantities(exporterIFC, spaceHnd, "GSA Space Areas", (isArea ? "GSA Design Gross Area" : "GSA BIM Area"), dArea);
            }

            // Export BaseQuantities for SpatialElement
            if (ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities && !(ExporterCacheManager.ExportOptionsCache.FileVersion == IFCVersion.IFCCOBIE))
            {
                ExporterIFCUtils.CreateNonCOBIERoomQuantities(exporterIFC, spaceHnd, spatialElement, dArea, roomHeight);
            }

            // Export Classifications for SpatialElement for GSA/COBIE.
            if (ExporterCacheManager.ExportOptionsCache.FileVersion == IFCVersion.IFCCOBIE)
            {
                CreateCOBIESpaceClassifications(exporterIFC, file, spaceHnd, document.ProjectInformation, spatialElement);
            }

            return true;
        }
Пример #48
0
        /// <summary>
        ///  Creates a new IfcAnnotation object.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="curveElement">The curve element.</param>
        /// <param name="categoryId">The category id.</param>
        /// <param name="sketchPlaneId">The sketch plane id.</param>
        /// <param name="refPlane">The reference plane.</param>
        /// <param name="curveStyle">The curve style.</param>
        /// <param name="placementSetter">The placemenet setter.</param>
        /// <param name="localPlacement">The local placement.</param>
        /// <param name="repItemHnd">The representation item.</param>
        /// <returns>The handle.</returns>
        static IFCAnyHandle CreateCurveAnnotation(ExporterIFC exporterIFC, Element curveElement, ElementId categoryId, ElementId sketchPlaneId,
                                                  Plane refPlane, IFCAnyHandle curveStyle, IFCPlacementSetter placementSetter, IFCAnyHandle localPlacement, IFCAnyHandle repItemHnd)
        {
            HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>();

            bodyItems.Add(repItemHnd);
            IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateAnnotationSetRep(exporterIFC, curveElement, categoryId, exporterIFC.Get2DContextHandle(), bodyItems);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd))
            {
                throw new Exception("Failed to create shape representation.");
            }

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

            shapes.Add(bodyRepHnd);

            IFCFile      file         = exporterIFC.GetFile();
            IFCAnyHandle prodShapeHnd = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapes);

            XYZ xDir = refPlane.XVec; XYZ zDir = refPlane.Normal; XYZ origin = refPlane.Origin;

            // subtract out level origin if we didn't already before.
            IFCLevelInfo levelInfo = placementSetter.GetLevelInfo();

            if (levelInfo != null && !MathUtil.IsAlmostEqual(zDir.Z, 1.0))
            {
                zDir -= new XYZ(0, 0, levelInfo.Elevation);
            }

            origin = origin * exporterIFC.LinearScale;
            IFCAnyHandle relativePlacement = ExporterUtil.CreateAxis(file, origin, zDir, xDir);

            GeometryUtil.SetRelativePlacement(localPlacement, relativePlacement);

            IFCAnyHandle annotation = IFCInstanceExporter.CreateAnnotation(file, ExporterIFCUtils.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                                                                           null, null, null, localPlacement, prodShapeHnd);

            return(annotation);
        }
        /// <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 ProductWrapper.</param>
        private static void ExportBase(ExporterIFC exporterIFC, ICollection <ElementId> allSubElements, Element element, ProductWrapper wrapper)
        {
            IFCFile      file         = exporterIFC.GetFile();
            IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();

            IFCPlacementSetter setter = null;

            using (ProductWrapper curtainWallSubWrapper = ProductWrapper.Create(wrapper, false))
            {
                try
                {
                    Transform    orientationTrf = Transform.Identity;
                    IFCAnyHandle localPlacement = null;
                    setter         = IFCPlacementSetter.Create(exporterIFC, element, null, orientationTrf, ExporterUtil.GetBaseLevelIdForElement(element));
                    localPlacement = setter.GetPlacement();

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

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

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

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

                    bool         canExportCurtainWallAsContainer = CanExportCurtainWallAsContainer(allSubElements, element.Document);
                    IFCAnyHandle rep = null;
                    if (!canExportCurtainWallAsContainer)
                    {
                        rep = ExportCurtainObjectCommonAsOneBRep(allSubElements, element, exporterIFC, setter, localPlacement);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(rep))
                        {
                            return;
                        }
                    }
                    else
                    {
                        ExportCurtainObjectCommonAsContainer(allSubElements, element, exporterIFC, curtainWallSubWrapper, setter);
                    }

                    ICollection <IFCAnyHandle> relatedElementIds = curtainWallSubWrapper.GetAllObjects();
                    if (relatedElementIds.Count > 0)
                    {
                        string guid = GUIDUtil.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);

                    ExportCurtainWallType(exporterIFC, wrapper, elemHnd, element);
                }
                finally
                {
                    if (setter != null)
                    {
                        setter.Dispose();
                    }
                }
            }
        }
Пример #50
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();
                }
            }
        }
        /// <summary>
        /// Exports curtain object as container.
        /// </summary>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="wallElement">
        /// The curtain wall element.
        /// </param>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void ExportCurtainObjectCommonAsContainer(ICollection <ElementId> allSubElements, Element wallElement,
                                                                ExporterIFC exporterIFC, ProductWrapper origWrapper, IFCPlacementSetter currSetter)
        {
            if (wallElement == null)
            {
                return;
            }

            string overrideCADLayer = null;

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

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

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

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

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

                            try
                            {
                                if (subElem is FamilyInstance)
                                {
                                    if (subElem is Mullion)
                                    {
                                        if (exporterIFC.ExportAs2x2)
                                        {
                                            ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper);
                                        }
                                        else
                                        {
                                            IFCAnyHandle currLocalPlacement = currSetter.GetPlacement();
                                            MullionExporter.Export(exporterIFC, subElem as Mullion, geomElem, currLocalPlacement, currSetter,
                                                                   productWrapper);
                                        }
                                    }
                                    else
                                    {
                                        FamilyInstance subFamInst = subElem as FamilyInstance;

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


                                        if (ExporterCacheManager.ExportOptionsCache.ExportAs2x2)
                                        {
                                            if ((exportType == IFCExportType.DontExport) || (exportType == IFCExportType.ExportPlateType) ||
                                                (exportType == IFCExportType.ExportMemberType))
                                            {
                                                exportType = IFCExportType.ExportBuildingElementProxyType;
                                            }
                                        }
                                        else
                                        {
                                            if (exportType == IFCExportType.DontExport)
                                            {
                                                ifcEnumType = "CURTAIN_PANEL";
                                                exportType  = IFCExportType.ExportPlateType;
                                            }
                                        }

                                        IFCAnyHandle currLocalPlacement = currSetter.GetPlacement();
                                        using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                                        {
                                            FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem(exporterIFC, subFamInst, exportType, ifcEnumType, productWrapper,
                                                                                                    ElementId.InvalidElementId, null, currLocalPlacement);
                                        }
                                    }
                                }
                                else if (subElem is CurtainGridLine)
                                {
                                    ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper);
                                }
                                else if (subElem is Wall)
                                {
                                    WallExporter.ExportWall(exporterIFC, subElem, geomElem, productWrapper);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ExporterUtil.IsFatalException(wallElement.Document, ex))
                                {
                                    throw ex;
                                }
                                continue;
                            }
                        }
                    }
                }
            }
        }
Пример #52
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 ProductWrapper.
        /// </param>
        public static void ExportCovering(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, string ifcEnumType, ProductWrapper 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, null, null, ExporterUtil.GetBaseLevelIdForElement(element)))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

                        IFCAnyHandle prodRep = null;
                        if (!exportParts)
                        {
                            ecData.SetLocalPlacement(setter.GetPlacement());
                            ecData.PossibleExtrusionAxes = IFCExtrusionAxes.TryZ;

                            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                            prodRep = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC, element,
                                                                                                 categoryId, geomElem, bodyExporterOptions, null, ecData, true);
                            if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodRep))
                            {
                                ecData.ClearOpenings();
                                return;
                            }
                        }
                        // We will use the category of the element to set a default value for the covering.
                        if (string.IsNullOrEmpty(ifcEnumType))
                        {
                            if (categoryId == new ElementId(BuiltInCategory.OST_Ceilings))
                            {
                                ifcEnumType = "CEILING";
                            }
                            else if (categoryId == new ElementId(BuiltInCategory.OST_Floors))
                            {
                                ifcEnumType = "FLOORING";
                            }
                            else if (categoryId == new ElementId(BuiltInCategory.OST_Roofs))
                            {
                                ifcEnumType = "ROOFING";
                            }
                        }

                        string instanceGUID                  = GUIDUtil.CreateGUID(element);
                        string instanceName                  = NamingUtil.GetIFCName(element);
                        string instanceDescription           = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceObjectType            = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName());
                        string instanceElemId                = NamingUtil.GetTagOverride(element, 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);
                        }

                        bool         containInSpace      = false;
                        IFCAnyHandle localPlacementToUse = setter.GetPlacement();

                        // Ceiling containment in Space is generally required and not specific to any view
                        if (ExporterCacheManager.CeilingSpaceRelCache.ContainsKey(element.Id))
                        {
                            IList <ElementId> roomlist = ExporterCacheManager.CeilingSpaceRelCache[element.Id];

                            // Process Ceiling to be contained in a Space only when it is exactly bounding one Space
                            if (roomlist.Count == 1)
                            {
                                productWrapper.AddElement(element, covering, setter, null, false);

                                // Modify the Ceiling placement to be relative to the Space that it bounds
                                IFCAnyHandle roomPlacement     = IFCAnyHandleUtil.GetObjectPlacement(ExporterCacheManager.SpatialElementHandleCache.Find(roomlist[0]));
                                Transform    relTrf            = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(roomPlacement, localPlacementToUse);
                                Transform    inverseTrf        = relTrf.Inverse;
                                IFCAnyHandle relLocalPlacement = ExporterUtil.CreateAxis2Placement3D(file, inverseTrf.Origin, inverseTrf.BasisZ, inverseTrf.BasisX);
                                IFCAnyHandleUtil.SetAttribute(localPlacementToUse, "PlacementRelTo", roomPlacement);
                                GeometryUtil.SetRelativePlacement(localPlacementToUse, relLocalPlacement);

                                exporterIFC.RelateSpatialElement(roomlist[0], covering);
                                containInSpace = true;
                            }
                        }

                        // if not contained in Space, assign it to default containment in Level
                        if (!containInSpace)
                        {
                            productWrapper.AddElement(element, covering, setter, null, true);
                        }

                        if (!exportParts)
                        {
                            Ceiling ceiling = element as Ceiling;
                            if (ceiling != null)
                            {
                                HostObjectExporter.ExportHostObjectMaterials(exporterIFC, ceiling, covering,
                                                                             geomElem, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, null);
                            }
                            else
                            {
                                ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geomElem, exporterIFC, element);
                                CategoryUtil.CreateMaterialAssociation(exporterIFC, covering, matId);
                            }
                        }

                        OpeningUtil.CreateOpeningsIfNecessary(covering, element, ecData, null,
                                                              exporterIFC, ecData.GetLocalPlacement(), setter, productWrapper);
                    }
                }
                transaction.Commit();
            }
        }
Пример #53
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();
            }
        }
Пример #54
0
        private static IFCAnyHandle FallbackTryToCreateAsExtrusion(ExporterIFC exporterIFC, Wall wallElement, SolidMeshGeometryInfo smCapsule,
            ElementId catId, Curve curve, Plane plane, double depth, IFCRange zSpan, IFCRange range, IFCPlacementSetter setter, 
            out IList<IFCExtrusionData> cutPairOpenings, out bool isCompletelyClipped)
        {
            cutPairOpenings = new List<IFCExtrusionData>();

            IFCAnyHandle bodyRep;
            isCompletelyClipped = false;

            XYZ localOrig = plane.Origin;

            bool hasExtrusion = HasElevationProfile(wallElement);
            if (hasExtrusion)
            {
                IList<CurveLoop> loops = GetElevationProfile(wallElement);
                if (loops.Count == 0)
                    hasExtrusion = false;
                else
                {
                    IList<IList<CurveLoop>> sortedLoops = ExporterIFCUtils.SortCurveLoops(loops);
                    if (sortedLoops.Count == 0)
                        return null;

                    // Current limitation: can't handle wall split into multiple disjointed pieces.
                    int numSortedLoops = sortedLoops.Count;
                    if (numSortedLoops > 1)
                        return null;

                    bool ignoreExtrusion = true;
                    bool cantHandle = false;
                    bool hasGeometry = false;
                    for (int ii = 0; (ii < numSortedLoops) && !cantHandle; ii++)
                    {
                        int sortedLoopSize = sortedLoops[ii].Count;
                        if (sortedLoopSize == 0)
                            continue;
                        if (!ExporterIFCUtils.IsCurveLoopConvexWithOpenings(sortedLoops[ii][0], wallElement, range, out ignoreExtrusion))
                        {
                            if (ignoreExtrusion)
                            {
                                // we need more information.  Is there something to export?  If so, we'll
                                // ignore the extrusion.  Otherwise, we will fail.

                                if (smCapsule.SolidsCount() == 0 && smCapsule.MeshesCount() == 0)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                cantHandle = true;
                            }
                            hasGeometry = true;
                        }
                        else
                        {
                            hasGeometry = true;
                        }
                    }

                    if (!hasGeometry)
                    {
                        isCompletelyClipped = true;
                        return null;
                    }

                    if (cantHandle)
                        return null;
                }
            }

            if (!CanExportWallGeometryAsExtrusion(wallElement, range))
                return null;

            // extrusion direction.
            XYZ extrusionDir = GetWallHeightDirection(wallElement);

            // create extrusion boundary.
            IList<CurveLoop> boundaryLoops = new List<CurveLoop>();

            bool alwaysThickenCurve = IsWallBaseRectangular(wallElement, curve);

            if (!alwaysThickenCurve)
            {
                boundaryLoops = GetLoopsFromTopBottomFace(wallElement, exporterIFC);
                if (boundaryLoops.Count == 0)
                    return null;
            }
            else
            {
                CurveLoop newLoop = CurveLoop.CreateViaThicken(curve, wallElement.Width, XYZ.BasisZ);
                if (newLoop == null)
                    return null;

                if (!newLoop.IsCounterclockwise(XYZ.BasisZ))
                    newLoop = GeometryUtil.ReverseOrientation(newLoop);
                boundaryLoops.Add(newLoop);
            }

            // origin gets scaled later.
            XYZ setterOffset = new XYZ(0, 0, setter.Offset + (localOrig[2] - setter.BaseOffset));

            IFCAnyHandle baseBodyItemHnd = ExtrusionExporter.CreateExtrudedSolidFromCurveLoop(exporterIFC, null, boundaryLoops, plane,
                extrusionDir, depth);
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(baseBodyItemHnd))
                return null;

            IFCAnyHandle bodyItemHnd = AddClippingsToBaseExtrusion(exporterIFC, wallElement,
               setterOffset, range, zSpan, baseBodyItemHnd, out cutPairOpenings);
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyItemHnd))
                return null;

            IFCAnyHandle styledItemHnd = BodyExporter.CreateSurfaceStyleForRepItem(exporterIFC, wallElement.Document,
                baseBodyItemHnd, ElementId.InvalidElementId);

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

            IFCAnyHandle contextOfItemsBody = exporterIFC.Get3DContextHandle("Body");
            if (baseBodyItemHnd.Id == bodyItemHnd.Id)
            {
                bodyRep = RepresentationUtil.CreateSweptSolidRep(exporterIFC, wallElement, catId, contextOfItemsBody, bodyItems, null);
            }
            else
            {
                bodyRep = RepresentationUtil.CreateClippingRep(exporterIFC, wallElement, catId, contextOfItemsBody, bodyItems);
            }

            return bodyRep;
        }
Пример #55
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>
        /// Exports an element as an IfcReinforcingMesh.
        /// </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 ProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportFabricSheet(ExporterIFC exporterIFC, FabricSheet sheet,
                                             GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            if (sheet == null || geometryElement == null)
            {
                return(false);
            }

            Document doc  = sheet.Document;
            IFCFile  file = exporterIFC.GetFile();

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

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(sheet);

                        ElementId materialId = ElementId.InvalidElementId;
                        ParameterUtil.GetElementIdValueFromElementOrSymbol(sheet, BuiltInParameter.MATERIAL_ID_PARAM, out materialId);
                        double scale = exporterIFC.LinearScale;

                        string       guid            = GUIDUtil.CreateGUID(sheet);
                        IFCAnyHandle ownerHistory    = exporterIFC.GetOwnerHistoryHandle();
                        string       revitObjectType = exporterIFC.GetFamilyName();
                        string       name            = NamingUtil.GetNameOverride(sheet, revitObjectType);
                        string       description     = NamingUtil.GetDescriptionOverride(sheet, null);
                        string       objectType      = NamingUtil.GetObjectTypeOverride(sheet, revitObjectType);

                        IFCAnyHandle localPlacement = ecData.GetLocalPlacement();
                        string       elementTag     = NamingUtil.CreateIFCElementId(sheet);

                        string steelGrade = NamingUtil.GetOverrideStringValue(sheet, "SteelGrade", null);
                        double?meshLength = sheet.CutOverallLength;
                        double?meshWidth  = sheet.CutOverallWidth;

                        Element         fabricSheetTypeElem = doc.GetElement(sheet.GetTypeId());
                        FabricSheetType fabricSheetType     = (fabricSheetTypeElem == null) ? null : (fabricSheetTypeElem as FabricSheetType);

                        double longitudinalBarNominalDiameter  = 0.0;
                        double transverseBarNominalDiameter    = 0.0;
                        double longitudinalBarCrossSectionArea = 0.0;
                        double transverseBarCrossSectionArea   = 0.0;
                        double longitudinalBarSpacing          = 0.0;
                        double transverseBarSpacing            = 0.0;
                        if (fabricSheetType != null)
                        {
                            Element        majorFabricWireTypeElem = doc.GetElement(fabricSheetType.MajorDirectionWireType);
                            FabricWireType majorFabricWireType     = (majorFabricWireTypeElem == null) ? null : (majorFabricWireTypeElem as FabricWireType);
                            if (majorFabricWireType != null)
                            {
                                longitudinalBarNominalDiameter = majorFabricWireType.WireDiameter * scale;
                                double localRadius = longitudinalBarNominalDiameter / 2.0;
                                longitudinalBarCrossSectionArea = localRadius * localRadius * Math.PI;
                            }

                            Element        minorFabricWireTypeElem = doc.GetElement(fabricSheetType.MinorDirectionWireType);
                            FabricWireType minorFabricWireType     = (minorFabricWireTypeElem == null) ? null : (minorFabricWireTypeElem as FabricWireType);
                            if (minorFabricWireType != null)
                            {
                                transverseBarNominalDiameter = minorFabricWireType.WireDiameter * scale;
                                double localRadius = transverseBarNominalDiameter / 2.0;
                                transverseBarCrossSectionArea = localRadius * localRadius * Math.PI;
                            }

                            longitudinalBarSpacing = fabricSheetType.MajorSpacing * scale;
                            transverseBarSpacing   = fabricSheetType.MinorSpacing * scale;
                        }

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

                        IList <Curve> wireCenterlines = sheet.GetWireCenterlines(WireDistributionDirection.Major);
                        foreach (Curve wireCenterline in wireCenterlines)
                        {
                            IFCAnyHandle bodyItem = CreateSweptDiskSolid(exporterIFC, file, wireCenterline, longitudinalBarNominalDiameter);
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(bodyItem))
                            {
                                bodyItems.Add(bodyItem);
                            }
                        }

                        wireCenterlines = sheet.GetWireCenterlines(WireDistributionDirection.Minor);
                        foreach (Curve wireCenterline in wireCenterlines)
                        {
                            IFCAnyHandle bodyItem = CreateSweptDiskSolid(exporterIFC, file, wireCenterline, transverseBarNominalDiameter);
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(bodyItem))
                            {
                                bodyItems.Add(bodyItem);
                            }
                        }

                        IFCAnyHandle shapeRep = (bodyItems.Count > 0) ?
                                                RepresentationUtil.CreateAdvancedSweptSolidRep(exporterIFC, sheet, categoryId, exporterIFC.Get3DContextHandle("Body"), bodyItems, null) :
                                                null;
                        IList <IFCAnyHandle> shapeReps = null;
                        if (shapeRep != null)
                        {
                            shapeReps = new List <IFCAnyHandle>();
                            shapeReps.Add(shapeRep);
                        }
                        IFCAnyHandle prodRep = (shapeReps != null) ? IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps) : null;

                        IFCAnyHandle fabricSheet = IFCInstanceExporter.CreateReinforcingMesh(file, guid,
                                                                                             ownerHistory, name, description, objectType, localPlacement, prodRep, elementTag,
                                                                                             steelGrade, meshLength, meshWidth, longitudinalBarNominalDiameter, transverseBarNominalDiameter,
                                                                                             longitudinalBarCrossSectionArea, transverseBarCrossSectionArea,
                                                                                             longitudinalBarSpacing, transverseBarSpacing);

                        ElementId fabricAreaId = sheet.FabricAreaOwnerId;
                        if (fabricAreaId != ElementId.InvalidElementId)
                        {
                            HashSet <IFCAnyHandle> fabricSheets = null;
                            if (!ExporterCacheManager.FabricAreaHandleCache.TryGetValue(fabricAreaId, out fabricSheets))
                            {
                                fabricSheets = new HashSet <IFCAnyHandle>();
                                ExporterCacheManager.FabricAreaHandleCache[fabricAreaId] = fabricSheets;
                            }
                            fabricSheets.Add(fabricSheet);
                        }

                        productWrapper.AddElement(sheet, fabricSheet, placementSetter.GetLevelInfo(), ecData, true);

                        CategoryUtil.CreateMaterialAssociation(exporterIFC, fabricSheet, materialId);
                    }
                }
                tr.Commit();
                return(true);
            }
        }
Пример #57
0
        /// <summary>
        /// Exports a generic family instance as IFC instance.
        /// </summary>
        /// <param name="type">The export type.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="familyInstance">The element.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        /// <param name="setter">The 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,
           ProductWrapper wrapper, IFCPlacementSetter setter, IFCExtrusionCreationData extraParams,
           string instanceGUID, IFCAnyHandle ownerHistory,
           string instanceName, string instanceDescription, string instanceObjectType,
           IFCAnyHandle productRepresentation,
           string instanceTag, IFCAnyHandle overrideLocalPlacement)
        {
            IFCFile file = exporterIFC.GetFile();
            Document doc = familyInstance.Document;

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

            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, instanceTag);
                        break;
                    }
                case IFCExportType.ExportMemberType:
                    {
                        instanceHandle = IFCInstanceExporter.CreateMember(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);

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

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

                        instanceHandle = IFCInstanceExporter.CreatePlate(file, instanceGUID, ownerHistory,
                            instanceName, instanceDescription, instanceObjectType, localPlacement, productRepresentation, instanceTag);
                        break;
                    }
                case IFCExportType.ExportDiscreteAccessoryType:
                    {
                        instanceHandle = IFCInstanceExporter.CreateDiscreteAccessory(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        break;
                    }
                case IFCExportType.ExportDistributionControlElement:
                    {
                        instanceHandle = IFCInstanceExporter.CreateDistributionControlElement(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                           null);
                        break;
                    }
                case IFCExportType.ExportDistributionElement:
                    {
                        instanceHandle = IFCInstanceExporter.CreateDistributionElement(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        break;
                    }
                case IFCExportType.ExportFastenerType:
                    {
                        instanceHandle = IFCInstanceExporter.CreateFastener(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        break;
                    }
                case IFCExportType.ExportMechanicalFastenerType:
                    {
                        double? nominalDiameter = null;
                        double? nominalLength = null;

                        double nominalDiameterVal, nominalLengthVal;

                        double scale = exporterIFC.LinearScale;

                        if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalDiameter", out nominalDiameterVal) != null)
                            nominalDiameter = nominalDiameterVal * scale;
                        if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalLength", out nominalLengthVal) != null)
                            nominalLength = nominalLengthVal * scale;

                        instanceHandle = IFCInstanceExporter.CreateMechanicalFastener(file, instanceGUID, ownerHistory,
                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                           nominalDiameter, nominalLength);
                        break;
                    }
                case IFCExportType.ExportRailingType:
                    {
                        string strEnumType;
                        IFCExportType exportAs = ExporterUtil.GetExportType(exporterIFC, familyInstance, out strEnumType);
                        instanceHandle = IFCInstanceExporter.CreateRailing(file, instanceGUID, ownerHistory, instanceName, instanceDescription,
                                instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                                RailingExporter.GetIFCRailingType(familyInstance, strEnumType));
                        break;
                    }
                case IFCExportType.ExportSpace:
                    {
                        string instanceLongName = NamingUtil.GetLongNameOverride(familyInstance, NamingUtil.GetLongNameOverride(familyInstance, instanceName));
                        IFCInternalOrExternal internalOrExternal = CategoryUtil.IsElementExternal(familyInstance) ? IFCInternalOrExternal.External : IFCInternalOrExternal.Internal;

                        instanceHandle = IFCInstanceExporter.CreateSpace(file, instanceGUID, ownerHistory, instanceName, instanceDescription,
                            instanceObjectType, localPlacementToUse, productRepresentation, instanceLongName, IFCElementComposition.Element,
                            internalOrExternal, null);
                        break;
                    }
                default:
                    {
                        if ((type == IFCExportType.ExportFurnishingElement) || IsFurnishingElementSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFurnishingElement(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportEnergyConversionDevice) || IsEnergyConversionDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateEnergyConversionDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowFitting) || IsFlowFittingSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowFitting(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowMovingDevice) || IsFlowMovingDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowMovingDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowSegment) || IsFlowSegmentSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowSegment(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowStorageDevice) || IsFlowStorageDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowStorageDevice(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowTerminal) || IsFlowTerminalSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowTerminal(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportFlowTreatmentDevice) || IsFlowTreatmentDeviceSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowTreatmentDevice(file, instanceGUID, ownerHistory,
                                   instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                            }
                        else if ((type == IFCExportType.ExportFlowController) || IsFlowControllerSubType(type))
                            {
                            instanceHandle = IFCInstanceExporter.CreateFlowController(file, instanceGUID, ownerHistory,
                                   instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                            }
                        else if ((type == IFCExportType.ExportDistributionFlowElement) || IsDistributionFlowElementSubType(type))
                        {
                            instanceHandle = IFCInstanceExporter.CreateDistributionFlowElement(file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if ((type == IFCExportType.ExportBuildingElementProxy) || (type == IFCExportType.ExportBuildingElementProxyType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateBuildingElementProxy(file, instanceGUID, ownerHistory,
                                   instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag, null);
                        }
                        break;
                    }
            }

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle))
            {
                bool containedInSpace = (roomId != ElementId.InvalidElementId);
                bool associateToLevel = containedInSpace ? false : !isChildInContainer;
                wrapper.AddElement(familyInstance, instanceHandle, setter, extraParams, associateToLevel);
                if (containedInSpace)
                    exporterIFC.RelateSpatialElement(roomId, instanceHandle);
            }
            return instanceHandle;
        }