Ejemplo n.º 1
0
        public override void ExecuteCmdlet()
        {
            if (AsJob.IsPresent)
            {
                DoBeginProcessing();
            }

            string   filePath  = this.Source;
            FileInfo localFile = new FileInfo(filePath);

            if (!localFile.Exists)
            {
                throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.Source));
            }

            // if FIPS policy is enabled, must use native MD5
            if (fipsEnabled)
            {
                CloudStorageAccount.UseV1MD5 = false;
            }

            bool isDirectory;

            string[] path = NamingUtil.ValidatePath(this.Path, out isDirectory);
            var      cloudFileToBeUploaded =
                BuildCloudFileInstanceFromPathAsync(localFile.Name, path, isDirectory).ConfigureAwait(false).GetAwaiter().GetResult();

            if (ShouldProcess(cloudFileToBeUploaded.Name, "Set file content"))
            {
                // Step 2: Build the CloudFile object which pointed to the
                // destination cloud file.
                this.RunTask(async taskId =>
                {
                    var progressRecord = new ProgressRecord(
                        this.OutputStream.GetProgressId(taskId),
                        string.Format(CultureInfo.CurrentCulture, Resources.SendAzureFileActivity, localFile.Name,
                                      cloudFileToBeUploaded.GetFullPath(), cloudFileToBeUploaded.Share.Name),
                        Resources.PrepareUploadingFile);

                    await DataMovementTransferHelper.DoTransfer(() =>
                                                                this.TransferManager.UploadAsync(
                                                                    localFile.FullName,
                                                                    cloudFileToBeUploaded,
                                                                    null,
                                                                    this.GetTransferContext(progressRecord, localFile.Length),
                                                                    this.CmdletCancellationToken),
                                                                progressRecord,
                                                                this.OutputStream).ConfigureAwait(false);


                    if (this.PassThru)
                    {
                        this.OutputStream.WriteObject(taskId, cloudFileToBeUploaded);
                    }
                });
            }

            if (AsJob.IsPresent)
            {
                DoEndProcessing();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Base implementation to export IFC site object.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="document">The Revit document.  It may be null if element isn't.</param>
        /// <param name="element">The element.  It may be null if document isn't.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        private static void ExportSiteBase(ExporterIFC exporterIFC, Document document, Element element, GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            IFCAnyHandle siteHandle = exporterIFC.GetSite();

            int numSiteElements = (!IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle) ? 1 : 0);

            if (element == null && (numSiteElements != 0))
            {
                return;
            }

            Document doc = document;

            if (doc == null)
            {
                if (element != null)
                {
                    doc = element.Document;
                }
                else
                {
                    throw new ArgumentException("Both document and element are null.");
                }
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                IFCAnyHandle siteRepresentation = null;
                if (element != null)
                {
                    // It would be possible that they actually represent several different sites with different buildings,
                    // but until we have a concept of a building in Revit, we have to assume 0-1 sites, 1 building.
                    bool appendedToSite     = false;
                    bool exportAsFacetation = !ExporterCacheManager.ExportOptionsCache.ExportAs2x3CoordinationView2;
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle))
                    {
                        IList <IFCAnyHandle> representations = IFCAnyHandleUtil.GetProductRepresentations(siteHandle);
                        if (representations.Count > 0)
                        {
                            IFCAnyHandle bodyRep     = representations[0];
                            IFCAnyHandle boundaryRep = null;
                            if (representations.Count > 1)
                            {
                                boundaryRep = representations[1];
                            }

                            siteRepresentation = RepresentationUtil.CreateSurfaceProductDefinitionShape(exporterIFC, element, geometryElement, true, exportAsFacetation, ref bodyRep, ref boundaryRep);
                            if (representations.Count == 1 && !IFCAnyHandleUtil.IsNullOrHasNoValue(boundaryRep))
                            {
                                // If the first site has no boundaryRep,
                                // we will add the boundaryRep from second site to it.
                                representations.Clear();
                                representations.Add(boundaryRep);
                                IFCAnyHandleUtil.AddProductRepresentations(siteHandle, representations);
                            }
                            appendedToSite = true;
                        }
                    }

                    if (!appendedToSite)
                    {
                        siteRepresentation = RepresentationUtil.CreateSurfaceProductDefinitionShape(exporterIFC, element, geometryElement, true, exportAsFacetation);
                    }
                }

                List <int>      latitude     = new List <int>();
                List <int>      longitude    = new List <int>();
                ProjectLocation projLocation = doc.ActiveProjectLocation;

                IFCAnyHandle relativePlacement = null;
                double       unscaledElevation = 0.0;
                if (projLocation != null)
                {
                    double latitudeInDeg  = projLocation.SiteLocation.Latitude * 180 / Math.PI;
                    double longitudeInDeg = projLocation.SiteLocation.Longitude * 180 / Math.PI;


                    ProjectPosition projectPosition = projLocation.get_ProjectPosition(XYZ.Zero);
                    unscaledElevation = projectPosition.Elevation;

                    int latDeg     = ((int)latitudeInDeg); latitudeInDeg -= latDeg; latitudeInDeg *= 60;
                    int latMin     = ((int)latitudeInDeg); latitudeInDeg -= latMin; latitudeInDeg *= 60;
                    int latSec     = ((int)latitudeInDeg); latitudeInDeg -= latSec; latitudeInDeg *= 1000000;
                    int latFracSec = ((int)latitudeInDeg);
                    latitude.Add(latDeg);
                    latitude.Add(latMin);
                    latitude.Add(latSec);
                    if (!exporterIFC.ExportAs2x2)
                    {
                        latitude.Add(latFracSec);
                    }

                    int longDeg     = ((int)longitudeInDeg); longitudeInDeg -= longDeg; longitudeInDeg *= 60;
                    int longMin     = ((int)longitudeInDeg); longitudeInDeg -= longMin; longitudeInDeg *= 60;
                    int longSec     = ((int)longitudeInDeg); longitudeInDeg -= longSec; longitudeInDeg *= 1000000;
                    int longFracSec = ((int)longitudeInDeg);
                    longitude.Add(longDeg);
                    longitude.Add(longMin);
                    longitude.Add(longSec);
                    if (!exporterIFC.ExportAs2x2)
                    {
                        longitude.Add(longFracSec);
                    }

                    Transform siteSharedCoordinatesTrf = projLocation.GetTransform().Inverse;
                    if (!siteSharedCoordinatesTrf.IsIdentity)
                    {
                        double unscaledSiteElevation = ExporterCacheManager.ExportOptionsCache.IncludeSiteElevation ? 0.0 : unscaledElevation;
                        XYZ    orig = siteSharedCoordinatesTrf.Origin - new XYZ(0, 0, unscaledSiteElevation);
                        orig = orig.Multiply(exporterIFC.LinearScale);
                        relativePlacement = ExporterUtil.CreateAxis2Placement3D(file, orig, siteSharedCoordinatesTrf.BasisZ, siteSharedCoordinatesTrf.BasisX);
                    }
                }

                // Get elevation for site.
                double elevation = unscaledElevation * exporterIFC.LinearScale;

                if (IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement))
                {
                    relativePlacement = ExporterUtil.CreateAxis2Placement3D(file);
                }

                IFCAnyHandle localPlacement = IFCInstanceExporter.CreateLocalPlacement(file, null, relativePlacement);
                IFCAnyHandle ownerHistory   = exporterIFC.GetOwnerHistoryHandle();
                string       siteObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, element);

                ProjectInfo projectInfo     = doc.ProjectInformation;
                Element     mainSiteElement = (element != null) ? element : projectInfo;

                bool   exportSite          = false;
                string siteGUID            = null;
                string siteName            = null;
                string siteLongName        = null;
                string siteLandTitleNumber = null;
                string siteDescription     = null;

                if (element != null)
                {
                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle))
                    {
                        exportSite = true;

                        // We will use the Project Information site name as the primary name, if it exists.
                        siteGUID = GUIDUtil.CreateSiteGUID(doc, element);

                        siteName        = NamingUtil.GetOverrideStringValue(projectInfo, "SiteName", NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element)));
                        siteDescription = NamingUtil.GetDescriptionOverride(element, null);
                        siteObjectType  = NamingUtil.GetObjectTypeOverride(element, siteObjectType);

                        // Look in site element for "IfcLongName" or project information for either "IfcLongName" or "SiteLongName".
                        siteLongName = NamingUtil.GetLongNameOverride(projectInfo, NamingUtil.GetLongNameOverride(element, null));
                        if (string.IsNullOrWhiteSpace(siteLongName))
                        {
                            siteLongName = NamingUtil.GetOverrideStringValue(projectInfo, "SiteLongName", null);
                        }

                        // Look in site element for "IfcLandTitleNumber" or project information for "SiteLandTitleNumber".
                        siteLandTitleNumber = NamingUtil.GetOverrideStringValue(element, "IfcLandTitleNumber", null);
                        if (string.IsNullOrWhiteSpace(siteLandTitleNumber))
                        {
                            siteLandTitleNumber = NamingUtil.GetOverrideStringValue(projectInfo, "SiteLandTitleNumber", null);
                        }
                    }
                }
                else
                {
                    exportSite = true;

                    siteGUID            = GUIDUtil.CreateProjectLevelGUID(doc, IFCProjectLevelGUIDType.Site);
                    siteName            = NamingUtil.GetOverrideStringValue(projectInfo, "SiteName", "Default");
                    siteLongName        = NamingUtil.GetLongNameOverride(projectInfo, NamingUtil.GetOverrideStringValue(projectInfo, "SiteLongName", null));
                    siteLandTitleNumber = NamingUtil.GetOverrideStringValue(projectInfo, "SiteLandTitleNumber", null);

                    // don't bother if we have nothing in the site whatsoever.
                    if ((latitude.Count == 0 || longitude.Count == 0) && IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement) &&
                        string.IsNullOrWhiteSpace(siteLongName) && string.IsNullOrWhiteSpace(siteLandTitleNumber))
                    {
                        return;
                    }
                }

                if (exportSite)
                {
                    siteHandle = IFCInstanceExporter.CreateSite(file, siteGUID, ownerHistory, siteName, siteDescription, siteObjectType, localPlacement,
                                                                siteRepresentation, siteLongName, Toolkit.IFCElementComposition.Element, latitude, longitude, elevation, siteLandTitleNumber, null);
                    productWrapper.AddSite(mainSiteElement, siteHandle);
                    exporterIFC.SetSite(siteHandle);
                }


                tr.Commit();
            }
        }
Ejemplo n.º 3
0
        /// <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 = ExporterCacheManager.OwnerHistoryHandle;

            PlacementSetter setter = null;

            using (ProductWrapper curtainWallSubWrapper = ProductWrapper.Create(wrapper, false))
            {
                try
                {
                    Transform    orientationTrf = Transform.Identity;
                    IFCAnyHandle localPlacement = null;
                    setter         = PlacementSetter.Create(exporterIFC, element, null, orientationTrf);
                    localPlacement = setter.LocalPlacement;

                    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);
                        ifcEnumType = IFCValidateEntry.GetValidIFCType(element, ifcEnumType);
                        elemHnd     = IFCInstanceExporter.CreateRoof(file, elemGUID, ownerHistory, elemName, elemDesc, elemType, localPlacement,
                                                                     prodRepHnd, elemTag, 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);
                    }

                    ExportCurtainWallType(exporterIFC, wrapper, elemHnd, element);
                    SpaceBoundingElementUtil.RegisterSpaceBoundingElementHandle(exporterIFC, elemHnd, element.Id, ElementId.InvalidElementId);
                }
                finally
                {
                    if (setter != null)
                    {
                        setter.Dispose();
                    }
                }
            }
        }
Ejemplo n.º 4
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();

            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.GetEndPoint(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 (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, canExportAxis ? orientTrf : null))
                {
                    IFCAnyHandle          localPlacement = setter.LocalPlacement;
                    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 = -UnitUtil.UnscaleLength(offsetTransform.Origin);
                            }
                            else
                            {
                                // Note that we do not have to have any scaling adjustment here, since the curve origin is in the
                                // same internal coordinate system as the curve.
                                curveOffset = -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));
                        string preDefinedType      = "BEAM"; // Default predefined type for Beam
                        preDefinedType = IFCValidateEntry.GetValidIFCType(element, preDefinedType);

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

                        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();
            }
        }
        /// <summary>
        /// Exports a Rebar Coupler,
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="coupler">The RebarCoupler element.</param>
        /// <param name="productWrapper">The product wrapper.</param>
        public static void ExportCoupler(ExporterIFC exporterIFC, RebarCoupler coupler, ProductWrapper productWrapper)
        {
            if (coupler == null)
            {
                return;
            }

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

            if (familySymbol == null)
            {
                return;
            }

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

            ElementId categoryId = CategoryUtil.GetSafeCategoryId(coupler);

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

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                FamilyTypeInfo currentTypeInfo = ExporterCacheManager.FamilySymbolToTypeInfoCache.Find(coupler.GetTypeId(), false, exportType);
                bool           found           = currentTypeInfo.IsValid();
                if (!found)
                {
                    string typeGUID            = GUIDUtil.CreateGUID(familySymbol);
                    string typeName            = NamingUtil.GetIFCName(familySymbol);
                    string typeObjectType      = NamingUtil.CreateIFCObjectName(exporterIFC, familySymbol);
                    string applicableOccurance = NamingUtil.GetObjectTypeOverride(familySymbol, typeObjectType);
                    string typeDescription     = NamingUtil.GetDescriptionOverride(familySymbol, null);
                    string typeElemId          = NamingUtil.CreateIFCElementId(familySymbol);

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

                    GeometryElement exportGeometry = familySymbol.get_Geometry(options);

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

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

                    IFCAnyHandle styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, ifcEnumType, typeGUID, typeName,
                                                                                    typeDescription, applicableOccurance, propertySetsOpt, repMap, typeElemId, typeName, coupler, familySymbol);

                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
                    {
                        currentTypeInfo.Style = styleHandle;
                        ExporterCacheManager.FamilySymbolToTypeInfoCache.Register(coupler.GetTypeId(), false, exportType, currentTypeInfo);
                    }
                }

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

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

                for (int idx = 0; idx < nCouplerQuantity; idx++)
                {
                    string instanceGUID        = GUIDUtil.CreateSubElementGUID(coupler, idx);
                    string instanceName        = NamingUtil.GetNameOverride(coupler, origInstanceName + ": " + idx);
                    string objectType          = NamingUtil.CreateIFCObjectName(exporterIFC, coupler);
                    string instanceObjectType  = NamingUtil.GetObjectTypeOverride(coupler, objectType);
                    string instanceDescription = NamingUtil.GetDescriptionOverride(coupler, null);
                    string instanceElemId      = NamingUtil.CreateIFCElementId(coupler);
                    string instanceTag         = NamingUtil.GetTagOverride(coupler, NamingUtil.CreateIFCElementId(coupler));

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

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

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

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

                    Transform trf = coupler.GetCouplerPositionTransform(idx);

                    using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, coupler, trf, null))
                    {
                        IFCAnyHandle instanceHandle = null;
                        instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(Common.Enums.IFCEntityType.IfcMechanicalFastener, file, instanceGUID, ownerHistory,
                                                                                    instanceName, instanceDescription, instanceObjectType, setter.LocalPlacement, productRepresentation, instanceTag);

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

                        createdRebarCouplerHandles.Add(instanceHandle);

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

                string couplerGUID = GUIDUtil.CreateGUID(coupler);

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

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

                        productWrapper.AddElement(coupler, rebarGroup);

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

                tr.Commit();
            }
        }
Ejemplo n.º 6
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);
        }
        private async Task <CloudFile> BuildCloudFileInstanceFromPathAsync(string defaultFileName, string[] path, bool pathIsDirectory)
        {
            CloudFileDirectory baseDirectory = null;
            bool isPathEmpty = path.Length == 0;

            switch (this.ParameterSetName)
            {
            case LocalConstants.DirectoryParameterSetName:
                baseDirectory = this.Directory;
                break;

            case LocalConstants.ShareNameParameterSetName:
                NamingUtil.ValidateShareName(this.ShareName, false);
                baseDirectory = this.BuildFileShareObjectFromName(this.ShareName).GetRootDirectoryReference();
                break;

            case LocalConstants.ShareParameterSetName:
                baseDirectory = this.Share.GetRootDirectoryReference();
                break;

            default:
                throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", this.ParameterSetName));
            }

            if (isPathEmpty)
            {
                return(baseDirectory.GetFileReference(defaultFileName));
            }

            var directory = baseDirectory.GetDirectoryReferenceByPath(path);

            if (pathIsDirectory)
            {
                return(directory.GetFileReference(defaultFileName));
            }

            bool directoryExists;

            try
            {
                directoryExists = await this.Channel.DirectoryExistsAsync(directory, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
            }
            catch (StorageException e)
            {
                if (e.RequestInformation != null &&
                    e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.BadRequest &&
                    e.RequestInformation.ExtendedErrorInformation == null)
                {
                    throw new AzureStorageFileException(ErrorCategory.InvalidArgument, ErrorIdConstants.InvalidResource, Resources.InvalidResource, this);
                }

                throw;
            }

            if (directoryExists)
            {
                // If the directory exist on the cloud, we treat the path as
                // to a directory. So we append the default file name after
                // it and build an instance of CloudFile class.
                return(directory.GetFileReference(defaultFileName));
            }
            else
            {
                // If the directory does not exist, we treat the path as to a
                // file. So we use the path of the directory to build out a
                // new instance of CloudFile class.
                return(baseDirectory.GetFileReferenceByPath(path));
            }
        }
Ejemplo n.º 8
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 PlacementSetter.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, Mullion mullion, GeometryElement geometryElement,
                                  IFCAnyHandle localPlacement, PlacementSetter setter, ProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (PlacementSetter mullionSetter = PlacementSetter.Create(exporterIFC, mullion))
            {
                using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                {
                    IFCAnyHandle mullionPlacement = mullionSetter.LocalPlacement;

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

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

                    extraParams.SetLocalPlacement(mullionLocalPlacement);

                    Transform extrusionLCS = null;
                    // Add a custom direction for trying to create an extrusion based on the base curve of the mullion, if it is a line and not an arc.
                    Curve baseCurve = mullion.LocationCurve;
                    if ((baseCurve != null) && (baseCurve is Line))
                    {
                        // We won't use curveBounds and origin yet; just need the axis for now.
                        IFCRange curveBounds;
                        XYZ      origin, mullionDirection;
                        GeometryUtil.GetAxisAndRangeFromCurve(baseCurve, out curveBounds, out mullionDirection, out origin);

                        // approx 1.0/sqrt(2.0)
                        XYZ planeY = (Math.Abs(mullionDirection.Z) < 0.707) ? XYZ.BasisZ.CrossProduct(mullionDirection) : XYZ.BasisX.CrossProduct(mullionDirection);
                        planeY.Normalize();

                        XYZ projDir = mullionDirection.CrossProduct(planeY);

                        extrusionLCS        = Transform.Identity;
                        extrusionLCS.BasisX = mullionDirection; extrusionLCS.BasisY = planeY; extrusionLCS.BasisZ = projDir; extrusionLCS.Origin = origin;
                    }

                    ElementId catId = CategoryUtil.GetSafeCategoryId(mullion);

                    BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                    bodyExporterOptions.ExtrusionLocalCoordinateSystem = extrusionLCS;

                    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, "MULLION");
                    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);
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Exports a Rebar to IFC ReinforcingBar.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="rebarItem">The rebar to be exported.  This might be an element or a sub-element.</param>
        /// <param name="rebarElement">The element that contains the rebar to be exported.  This may be the same as rebarItem.</param>
        /// <param name="itemIndex">If greater than 0, the index of the first rebar in the rebarItem in the rebarElement, used for naming and GUID creation.</param>
        /// <param name="productWrapper">The ProductWrapper object.</param>
        /// <returns>The set of handles created, to add to the ProductWrapper in the calling function.</returns>
        private static ISet <DelayedProductWrapper> ExportRebar(ExporterIFC exporterIFC, object rebarItem, Element rebarElement, int itemIndex, ProductWrapper productWrapper)
        {
            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcReinforcingBar;
            if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
            {
                return(null);
            }

            IFCFile file = exporterIFC.GetFile();
            HashSet <DelayedProductWrapper> createdRebars = new HashSet <DelayedProductWrapper>();

            int rebarQuantity = GetRebarQuantity(rebarItem);

            if (rebarQuantity == 0)
            {
                return(null);
            }

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, rebarElement))
                {
                    bool         cannotExportRebar = false;
                    IFCAnyHandle rebarHandle       = ExportRebarAsProxyElementInView(exporterIFC, rebarElement, productWrapper, out cannotExportRebar);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(rebarHandle) || cannotExportRebar)
                    {
                        if (!cannotExportRebar)
                        {
                            transaction.Commit();
                        }
                        return(null); // Rebar doesn't create a group.
                    }

                    IFCAnyHandle prodRep = null;

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

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

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

                    double diameter = GetBarDiameter(rebarItem);
                    double radius   = diameter / 2.0;
                    double longitudinalBarNominalDiameter  = diameter;
                    double longitudinalBarCrossSectionArea = UnitUtil.ScaleArea(volumeUnscale / totalBarLengthUnscale);

                    int numberOfBarPositions = GetNumberOfBarPositions(rebarItem);

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

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

                    string origRebarName = NamingUtil.GetNameOverride(rebarElement, NamingUtil.GetIFCName(rebarElement));

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

                    IFCAnyHandle originalPlacement = setter.LocalPlacement;

                    // Potential issue : totalBarLength has a rounded value but individual lengths (from centerlines) do not have rounded values.
                    // Also dividing a rounded totalBarLength does not result in barLength rounded by the same round value.
                    double        barLength  = totalBarLength / rebarQuantity;
                    IList <Curve> baseCurves = GetRebarCenterlineCurves(rebarItem, true, false, false);

                    ElementId    barLengthParamId   = new ElementId(BuiltInParameter.REBAR_ELEM_LENGTH);
                    ParameterSet rebarElementParams = rebarElement.Parameters;
                    for (int ii = 0; ii < numberOfBarPositions; ii++)
                    {
                        if (!DoesBarExistAtPosition(rebarItem, ii))
                        {
                            continue;
                        }

                        Rebar rebar = rebarElement as Rebar;
                        if ((rebar != null) && (rebar.DistributionType == DistributionType.VaryingLength || rebar.IsRebarFreeForm()))
                        {
                            baseCurves = GetRebarCenterlineCurves(rebar, true, false, false, MultiplanarOption.IncludeOnlyPlanarCurves, ii);
                            DoubleParameterValue barLengthParamVal = rebar.GetParameterValueAtIndex(barLengthParamId, ii) as DoubleParameterValue;
                            if (barLengthParamVal != null)
                            {
                                barLength = barLengthParamVal.Value;
                            }
                        }


                        string rebarNameFormated = origRebarName;
                        if (rebar != null && rebar.CanBeMatchedWithMultipleShapes())
                        {
                            string shapeName   = getShapeNameAtIndex(rebar, ii);
                            string elementName = rebar.Name;
                            string strVaries   = "";
                            if (!elementName.Contains(shapeName))
                            {
                                // it means that element name contains "Shape Varies"

                                // get "Varies" string from elem name
                                for (int iChar = elementName.Length - 1; iChar > 0; iChar--)
                                {
                                    if (elementName[iChar] == ' ')
                                    {
                                        break;
                                    }
                                    strVaries = strVaries.Insert(0, elementName[iChar].ToString());
                                }

                                // Replace "Varies" with shape name.
                                rebarNameFormated = origRebarName.Replace(strVaries, shapeName);
                            }
                        }

                        int indexForNamingAndGUID = (itemIndex > 0) ? ii + itemIndex : ii + 1;

                        string rebarName = NamingUtil.GetNameOverride(rebarElement, rebarNameFormated + ": " + indexForNamingAndGUID);

                        Transform barTrf = GetBarPositionTransform(rebarItem, ii);

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

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

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

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

                        string rebarGUID = (indexForNamingAndGUID < maxBarGUIDS) ?
                                           GUIDUtil.CreateSubElementGUID(rebarElement, indexForNamingAndGUID + (int)IFCReinforcingBarSubElements.BarStart - 1) :
                                           GUIDUtil.CreateGUID();
                        IFCAnyHandle elemHnd = IFCInstanceExporter.CreateReinforcingBar(exporterIFC, rebarElement, rebarGUID, ExporterCacheManager.OwnerHistoryHandle,
                                                                                        copyLevelPlacement, prodRep, steelGrade, longitudinalBarNominalDiameter, longitudinalBarCrossSectionArea, barLength, role, null);
                        IFCAnyHandleUtil.OverrideNameAttribute(elemHnd, rebarName);

                        // We will not add the element ot the productWrapper here, but instead in the function that calls
                        // ExportRebar.  The reason for this is that we don't currently know if the handles such be associated
                        // to the level or not, depending on whether they will or won't be grouped.
                        createdRebars.Add(new DelayedProductWrapper(rebarElement, elemHnd, setter.LevelInfo));

                        CacheSubelementParameterValues(rebarElement, rebarElementParams, ii, elemHnd);

                        ExporterCacheManager.HandleToElementCache.Register(elemHnd, rebarElement.Id);
                        CategoryUtil.CreateMaterialAssociation(exporterIFC, elemHnd, materialId);
                    }
                }
                transaction.Commit();
            }
            return(createdRebars);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Base implementation to export IFC site object.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="document">The Revit document.  It may be null if element isn't.</param>
        /// <param name="element">The element.  It may be null if document isn't.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        private static void ExportSiteBase(ExporterIFC exporterIFC, Document document, Element element, GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            IFCAnyHandle siteHandle = ExporterCacheManager.SiteHandle;

            // Nothing to do if we've already created an IfcSite, and have no site element to try to
            // export or append to the existing site.
            if (element == null && !IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle))
            {
                return;
            }

            Document doc = document;

            if (doc == null)
            {
                if (element != null)
                {
                    doc = element.Document;
                }
                else
                {
                    throw new ArgumentException("Both document and element are null.");
                }
            }

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

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                IFCAnyHandle siteRepresentation = null;
                if (element != null)
                {
                    // It would be possible that they actually represent several different sites with different buildings,
                    // but until we have a concept of a building in Revit, we have to assume 0-1 sites, 1 building.
                    bool appendedToSite     = false;
                    bool exportAsFacetation = !ExporterCacheManager.ExportOptionsCache.ExportAsCoordinationView2;
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle))
                    {
                        IList <IFCAnyHandle> representations = IFCAnyHandleUtil.GetProductRepresentations(siteHandle);
                        if (representations.Count > 0)
                        {
                            IFCAnyHandle bodyRep     = representations[0];
                            IFCAnyHandle boundaryRep = null;
                            if (representations.Count > 1)
                            {
                                boundaryRep = representations[1];
                            }

                            siteRepresentation = RepresentationUtil.CreateSurfaceProductDefinitionShape(exporterIFC, element, geometryElement, true, exportAsFacetation, ref bodyRep, ref boundaryRep);
                            if (representations.Count == 1 && !IFCAnyHandleUtil.IsNullOrHasNoValue(boundaryRep))
                            {
                                // If the first site has no boundaryRep,
                                // we will add the boundaryRep from second site to it.
                                representations.Clear();
                                representations.Add(boundaryRep);
                                IFCAnyHandleUtil.AddProductRepresentations(siteHandle, representations);
                            }
                            appendedToSite = true;
                        }
                    }

                    if (!appendedToSite)
                    {
                        siteRepresentation = RepresentationUtil.CreateSurfaceProductDefinitionShape(exporterIFC, element, geometryElement, true, exportAsFacetation);
                    }
                }

                List <int>      latitude     = new List <int>();
                List <int>      longitude    = new List <int>();
                ProjectLocation projLocation = doc.ActiveProjectLocation;

                double unscaledElevation = 0.0;
                if (projLocation != null)
                {
                    const double scaleToDegrees = 180 / Math.PI;
                    double       latitudeInDeg  = projLocation.GetSiteLocation().Latitude *scaleToDegrees;
                    double       longitudeInDeg = projLocation.GetSiteLocation().Longitude *scaleToDegrees;

                    ExporterUtil.GetSafeProjectPositionElevation(doc, out unscaledElevation);

                    int latDeg     = ((int)latitudeInDeg); latitudeInDeg -= latDeg; latitudeInDeg *= 60;
                    int latMin     = ((int)latitudeInDeg); latitudeInDeg -= latMin; latitudeInDeg *= 60;
                    int latSec     = ((int)latitudeInDeg); latitudeInDeg -= latSec; latitudeInDeg *= 1000000;
                    int latFracSec = ((int)latitudeInDeg);
                    latitude.Add(latDeg);
                    latitude.Add(latMin);
                    latitude.Add(latSec);
                    if (!ExporterCacheManager.ExportOptionsCache.ExportAs2x2)
                    {
                        latitude.Add(latFracSec);
                    }

                    int longDeg     = ((int)longitudeInDeg); longitudeInDeg -= longDeg; longitudeInDeg *= 60;
                    int longMin     = ((int)longitudeInDeg); longitudeInDeg -= longMin; longitudeInDeg *= 60;
                    int longSec     = ((int)longitudeInDeg); longitudeInDeg -= longSec; longitudeInDeg *= 1000000;
                    int longFracSec = ((int)longitudeInDeg);
                    longitude.Add(longDeg);
                    longitude.Add(longMin);
                    longitude.Add(longSec);
                    if (!ExporterCacheManager.ExportOptionsCache.ExportAs2x2)
                    {
                        longitude.Add(longFracSec);
                    }
                }

                // Get elevation for site.
                IFCAnyHandle relativePlacement = null;
                IFCAnyHandle localPlacement    = null;
                if (ExporterCacheManager.ExportOptionsCache.ExportingLink)
                {
                    relativePlacement = ExporterUtil.CreateAxis2Placement3D(file, UnitUtil.ScaleLength(ExporterCacheManager.HostRvtFileWCS.Origin), ExporterCacheManager.HostRvtFileWCS.BasisZ, ExporterCacheManager.HostRvtFileWCS.BasisX);
                    localPlacement    = IFCInstanceExporter.CreateLocalPlacement(file, null, relativePlacement);
                }
                else
                {
                    if (ExporterCacheManager.ExportOptionsCache.IncludeSiteElevation)
                    {
                        unscaledElevation = 0.0;
                    }
                    Transform wcs = GeometryUtil.GetWCS(doc, unscaledElevation);
                    if (wcs != null && !wcs.IsIdentity)
                    {
                        relativePlacement = ExporterUtil.CreateAxis2Placement3D(file, wcs.Origin, wcs.BasisZ, wcs.BasisX);
                        localPlacement    = IFCInstanceExporter.CreateLocalPlacement(file, null, relativePlacement);
                        ExporterCacheManager.HostRvtFileWCS        = wcs;
                        ExporterCacheManager.HostRvtFileWCS.Origin = UnitUtil.UnscaleLength(ExporterCacheManager.HostRvtFileWCS.Origin);
                    }
                    else
                    {
                        ExporterCacheManager.HostRvtFileWCS = Transform.Identity;
                    }
                }

                if (IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement))
                {
                    relativePlacement = ExporterUtil.CreateAxis2Placement3D(file);
                }

                if (IFCAnyHandleUtil.IsNullOrHasNoValue(localPlacement))
                {
                    localPlacement = IFCInstanceExporter.CreateLocalPlacement(file, null, relativePlacement);
                }

                IFCAnyHandle ownerHistory   = ExporterCacheManager.OwnerHistoryHandle;
                string       siteObjectType = null;

                ProjectInfo projectInfo     = doc.ProjectInformation;
                Element     mainSiteElement = (element != null) ? element : projectInfo;

                string siteGUID            = null;
                string siteName            = null;
                string siteLongName        = null;
                string siteLandTitleNumber = null;
                string siteDescription     = null;
                bool   exportSite          = false;

                if ((element != null && IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle)) || (element == null))
                {
                    exportSite = true;

                    // We will use the Project Information site name as the primary name, if it exists.
                    siteGUID = (element != null) ? GUIDUtil.CreateSiteGUID(doc, element) : GUIDUtil.CreateProjectLevelGUID(doc, GUIDUtil.ProjectLevelGUIDType.Site);;

                    if (element != null)
                    {
                        siteName            = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                        siteDescription     = NamingUtil.GetDescriptionOverride(element, null);
                        siteObjectType      = NamingUtil.GetObjectTypeOverride(element, null);
                        siteLongName        = NamingUtil.GetLongNameOverride(element, null);
                        siteLandTitleNumber = NamingUtil.GetOverrideStringValue(element, "IfcLandTitleNumber", null);
                    }
                    else
                    {
                        siteName = "Default";
                    }

                    siteName            = NamingUtil.GetOverrideStringValue(projectInfo, "SiteName", siteName);
                    siteDescription     = NamingUtil.GetOverrideStringValue(projectInfo, "SiteDescription", siteDescription);
                    siteObjectType      = NamingUtil.GetOverrideStringValue(projectInfo, "SiteObjectType", siteObjectType);
                    siteLongName        = NamingUtil.GetOverrideStringValue(projectInfo, "SiteLongName", siteLongName);
                    siteLandTitleNumber = NamingUtil.GetOverrideStringValue(projectInfo, "SiteLandTitleNumber", siteLandTitleNumber);

                    if (element == null)
                    {
                        // don't bother exporting if we have nothing in the site whatsoever, and it is virtual.
                        if ((latitude.Count == 0 || longitude.Count == 0) &&
                            IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement) &&
                            string.IsNullOrWhiteSpace(siteLongName) &&
                            string.IsNullOrWhiteSpace(siteLandTitleNumber))
                        {
                            return;
                        }
                    }
                }

                COBieProjectInfo cobieProjectInfo = ExporterCacheManager.ExportOptionsCache.COBieProjectInfo;
                // Override Site information when it is a special COBie export
                if (ExporterCacheManager.ExportOptionsCache.ExportAs2x3COBIE24DesignDeliverable && cobieProjectInfo != null)
                {
                    siteName        = cobieProjectInfo.SiteLocation;
                    siteDescription = cobieProjectInfo.SiteDescription;
                }

                if (exportSite)
                {
                    IFCAnyHandle address = null;
                    if (Exporter.NeedToCreateAddressForSite(doc))
                    {
                        address = Exporter.CreateIFCAddress(file, doc, projectInfo);
                    }

                    double elevation = UnitUtil.ScaleLength(unscaledElevation);

                    siteHandle = IFCInstanceExporter.CreateSite(exporterIFC, element, siteGUID, ownerHistory, siteName, siteDescription, siteObjectType, localPlacement,
                                                                siteRepresentation, siteLongName, IFCElementComposition.Element, latitude, longitude, elevation, siteLandTitleNumber, address);
                    productWrapper.AddSite(mainSiteElement, siteHandle);
                    ExporterCacheManager.SiteHandle = siteHandle;
                }


                tr.Commit();
            }
        }
Ejemplo n.º 11
0
        /// <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 (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, sheet))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(placementSetter.LocalPlacement);

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(sheet);

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

                        string       guid            = GUIDUtil.CreateGUID(sheet);
                        IFCAnyHandle ownerHistory    = ExporterCacheManager.OwnerHistoryHandle;
                        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 = UnitUtil.ScaleLength(majorFabricWireType.WireDiameter);
                                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 = UnitUtil.ScaleLength(minorFabricWireType.WireDiameter);
                                double localRadius = transverseBarNominalDiameter / 2.0;
                                transverseBarCrossSectionArea = localRadius * localRadius * Math.PI;
                            }

                            longitudinalBarSpacing = UnitUtil.ScaleLength(fabricSheetType.MajorSpacing);
                            transverseBarSpacing   = UnitUtil.ScaleLength(fabricSheetType.MinorSpacing);
                        }

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

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

                        wireCenterlines = sheet.GetWireCenterlines(WireDistributionDirection.Minor);
                        foreach (Curve wireCenterline in wireCenterlines)
                        {
                            IFCAnyHandle bodyItem = GeometryUtil.CreateSweptDiskSolid(exporterIFC, file, wireCenterline, transverseBarNominalDiameter, null);
                            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.LevelInfo, ecData, true);

                        CategoryUtil.CreateMaterialAssociation(exporterIFC, fabricSheet, materialId);
                    }
                }
                tr.Commit();
                return(true);
            }
        }
        /// <summary>
        /// Exports an element as an IFC assembly.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportAssemblyInstanceElement(ExporterIFC exporterIFC, AssemblyInstance element,
                                                         ProductWrapper productWrapper)
        {
            if (element == null)
            {
                return(false);
            }

            IFCFile file = exporterIFC.GetFile();

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

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

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

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

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

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

                    relateToLevel = false; // Already related to the building via IfcRelServicesBuildings.
                }
                else
                {
                    using (placementSetter = PlacementSetter.Create(exporterIFC, element))
                    {
                        string       elementTag     = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));
                        IFCAnyHandle representation = null;

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

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

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

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

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

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

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

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

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

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

                tr.Commit();
                return(true);
            }
        }
Ejemplo n.º 13
0
        private void Initialize()
        {
            /**
             * Please don't remove this line
             * This is the only eDriven.Gui line I'd like to have written in Your app log :)
             * It's interesting to see if application uses the framework
             * */
            if (Framework.EnableInfoMessages)
            {
                Debug.Log(string.Format(@"eDriven.Gui framework: instantiated: {0}", new Info()));
            }

#if DEBUG
            Debug.Log(string.Format(@"***** Debug build *****"));
#endif

#if TRIAL
            Debug.Log(string.Format(@"***** eDriven.Gui Free Edition *****"));
#endif

#if !RELEASE
            Debug.Log(string.Format(@"***** Not a realese build *****"));
#endif

            /**
             * 1) Connect to system manager clocks
             * */
            //SystemManager.Instance.UpdateSignal.Connect(_updateSlot, 0, false);

            //Debug.Log("*** SUBSCRIBING ***");
            SystemManager.Instance.RenderSignal.Connect(RenderSlot);
            SystemManager.Instance.ResizeSignal.Connect(ResizeSlot);
            SystemManager.Instance.SceneChangeSignal.Connect(SceneChangeSlot);
            //SystemManager.Instance.LevelInitSignal.Connect(LevelInitSlot);
            //SystemManager.Instance.LevelLoadedSignal.Connect(LevelInitSlot);
            //SystemManager.Instance.LevelLoadedSignal.Connect(LevelInitSlot);
            SystemManager.Instance.DisposingSignal.Connect(DisposingSlot, true); // auto disconnect

            /**
             * 3) let interested parties reference the stage list
             * */

            DragDropManager.StageList = _stageListDesc;

            CoordinateProcessor.StageListAsc  = _stageListAsc;
            CoordinateProcessor.StageListDesc = _stageListDesc;

            // initialize styles
            //StyleInitializer.Run();

#pragma warning disable 168
            //var med = MouseEventDispatcher.Instance;

// ReSharper disable UnusedVariable
            var fm = FocusManager.Instance;   // initialize listeners to mouse event manager
            var tm = TooltipManager.Instance; // initialize listeners to mouse event manager
            var km = KeyEventDispatcher.Instance;

            NamingUtil.Initialize();
            var cm = ComponentManager.Instance;
// ReSharper restore UnusedVariable

            /* Important! */
            // ReSharper disable once UnusedVariable
            var mq = MediaQueryManager.Instance;

// ReSharper disable once UnusedVariable
            var scm = StyleClientManager.Instance;

#pragma warning restore 168

#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("StageManager instantiated [width: {0}; height:{1}]", _size.X, _size.Y));
            }
#endif

#if TRIAL
            // check piracy
            //GenuineChecker.Check();
#endif

#if TRIAL
            _acme      = (Acme)Framework.GetComponent <Acme>(true);
            _lockStyle = LockButtonStyle.Instance;
            //if (!Application.isEditor) {
            _startTime = Time.time;
            System.Random random = new System.Random();
            _timeToWait = random.Next(10, 1200);     // 10s - / 1200 = 20 min
            if (Application.isEditor)
            {
                _timeToWait += 300;     // 5 minutes
            }
            //}
#endif
        }
Ejemplo n.º 14
0
 public override bool IsValidName(DeclaredElementType elementType, string name)
 {
     return(NamingUtil.IsIdentifier(name) || Uri.IsWellFormedUriString(name, UriKind.Absolute));
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Exports an element as a zone.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportZone(ExporterIFC exporterIFC, Zone element,
                                      ProductWrapper productWrapper)
        {
            if (element == null)
            {
                return;
            }

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

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

            SpaceSet spaces = element.Spaces;

            foreach (Space space in spaces)
            {
                if (space == null)
                {
                    continue;
                }

                IFCAnyHandle spaceHnd = ExporterCacheManager.SpaceInfoCache.FindSpaceHandle(space.Id);
                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(spaceHnd))
                {
                    spaceHnds.Add(spaceHnd);
                }
            }

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

            IFCFile file = exporterIFC.GetFile();

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

                IFCAnyHandle      zoneHnd    = IFCInstanceExporter.CreateZone(file, guid, ownerHistory, name, description, objectType, longName);
                IFCExportInfoPair exportInfo = new IFCExportInfoPair(elementClassTypeEnum);

                productWrapper.AddElement(element, zoneHnd, exportInfo);

                string relAssignsGuid = GUIDUtil.CreateSubElementGUID(element, (int)IFCZoneSubElements.RelAssignsToGroup);
                IFCInstanceExporter.CreateRelAssignsToGroup(file, relAssignsGuid, ownerHistory, null, null, spaceHnds, null, zoneHnd);

                tr.Commit();
                return;
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Exports a Rebar, AreaReinforcement or PathReinforcement to IFC ReinforcingBar.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The product wrapper.</param>
        public static void Export(ExporterIFC exporterIFC, Element element, ProductWrapper productWrapper)
        {
            ISet <DelayedProductWrapper> createdRebars = new HashSet <DelayedProductWrapper>();

            if (element is Rebar)
            {
                createdRebars = ExportRebar(exporterIFC, element, productWrapper);
            }
            else if (element is AreaReinforcement)
            {
                AreaReinforcement areaReinforcement = element as AreaReinforcement;
                IList <ElementId> rebarIds          = areaReinforcement.GetRebarInSystemIds();

                Document doc = areaReinforcement.Document;
                foreach (ElementId id in rebarIds)
                {
                    Element rebarInSystem = doc.GetElement(id);
                    ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper);
                    if (newlyCreatedRebars != null)
                    {
                        createdRebars.UnionWith(newlyCreatedRebars);
                    }
                }
            }
            else if (element is PathReinforcement)
            {
                PathReinforcement pathReinforcement = element as PathReinforcement;
                IList <ElementId> rebarIds          = pathReinforcement.GetRebarInSystemIds();

                Document doc = pathReinforcement.Document;
                foreach (ElementId id in rebarIds)
                {
                    Element rebarInSystem = doc.GetElement(id);
                    ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper);
                    if (newlyCreatedRebars != null)
                    {
                        createdRebars.UnionWith(newlyCreatedRebars);
                    }
                }
            }
            else if (element is RebarContainer)
            {
                int            itemIndex      = 1;
                RebarContainer rebarContainer = element as RebarContainer;
                foreach (RebarContainerItem rebarContainerItem in rebarContainer)
                {
                    ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarContainerItem, rebarContainer, itemIndex, productWrapper);
                    if (newlyCreatedRebars != null)
                    {
                        itemIndex += createdRebars.Count;
                        createdRebars.UnionWith(newlyCreatedRebars);
                    }
                }
            }

            if (createdRebars != null && createdRebars.Count != 0)
            {
                string guid = GUIDUtil.CreateGUID(element);

                // Create a group to hold all of the created IFC entities, if the rebars aren't already in an assembly or a group.
                // We want to avoid nested groups of groups of rebars.
                bool relateToLevel     = true;
                bool groupRebarHandles = (createdRebars.Count != 1);
                foreach (DelayedProductWrapper delayedProductWrapper in createdRebars)
                {
                    if (ElementIsContainedInAssembly(delayedProductWrapper.RebarElement))
                    {
                        groupRebarHandles = false;
                        relateToLevel     = false;
                        break;
                    }
                }

                ISet <IFCAnyHandle> createdRebarHandles = new HashSet <IFCAnyHandle>();
                foreach (DelayedProductWrapper delayedProductWrapper in createdRebars)
                {
                    IFCAnyHandle currentRebarHandle = delayedProductWrapper.ElementHandle;
                    productWrapper.AddElement(delayedProductWrapper.RebarElement, currentRebarHandle, delayedProductWrapper.LevelInfo, null, relateToLevel);
                    createdRebarHandles.Add(currentRebarHandle);
                }

                if (createdRebars.Count > 1)
                {
                    if (groupRebarHandles)
                    {
                        // Check the intended IFC entity or type name is in the exclude list specified in the UI
                        Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcGroup;
                        if (!ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                        {
                            IFCFile file = exporterIFC.GetFile();
                            using (IFCTransaction tr = new IFCTransaction(file))
                            {
                                IFCAnyHandle ownerHistory    = ExporterCacheManager.OwnerHistoryHandle;
                                string       revitObjectType = NamingUtil.GetFamilyAndTypeName(element);
                                string       name            = NamingUtil.GetNameOverride(element, revitObjectType);
                                string       description     = NamingUtil.GetDescriptionOverride(element, null);
                                string       objectType      = NamingUtil.GetObjectTypeOverride(element, revitObjectType);

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

                                productWrapper.AddElement(element, rebarGroup);

                                IFCInstanceExporter.CreateRelAssignsToGroup(file, GUIDUtil.CreateGUID(), ownerHistory,
                                                                            null, null, createdRebarHandles, null, rebarGroup);

                                tr.Commit();
                            }
                        }
                    }
                }
                else
                {
                    // We will update the GUID of the one created IfcReinforcingElement to be the element GUID.
                    // This will allow the IfcGUID parameter to be use/set if appropriate.
                    ExporterUtil.SetGlobalId(createdRebarHandles.ElementAt(0), guid);
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets IFCRoofType from roof type name.
        /// </summary>
        /// <param name="roofTypeName">The roof type name.</param>
        /// <returns>The IFCRoofType.</returns>
        public static string GetIFCRoofType(string roofTypeName)
        {
            string typeName = NamingUtil.RemoveSpacesAndUnderscores(roofTypeName);

            if (String.Compare(typeName, "ROOFTYPEENUM", true) == 0 ||
                String.Compare(typeName, "ROOFTYPEENUMFREEFORM", true) == 0)
            {
                return("FREEFORM");
            }
            if (String.Compare(typeName, "FLAT", true) == 0 ||
                String.Compare(typeName, "FLATROOF", true) == 0)
            {
                return("FLAT_ROOF");
            }
            if (String.Compare(typeName, "SHED", true) == 0 ||
                String.Compare(typeName, "SHEDROOF", true) == 0)
            {
                return("SHED_ROOF");
            }
            if (String.Compare(typeName, "GABLE", true) == 0 ||
                String.Compare(typeName, "GABLEROOF", true) == 0)
            {
                return("GABLE_ROOF");
            }
            if (String.Compare(typeName, "HIP", true) == 0 ||
                String.Compare(typeName, "HIPROOF", true) == 0)
            {
                return("HIP_ROOF");
            }
            if (String.Compare(typeName, "HIPPED_GABLE", true) == 0 ||
                String.Compare(typeName, "HIPPED_GABLEROOF", true) == 0)
            {
                return("HIPPED_GABLE_ROOF");
            }
            if (String.Compare(typeName, "MANSARD", true) == 0 ||
                String.Compare(typeName, "MANSARDROOF", true) == 0)
            {
                return("MANSARD_ROOF");
            }
            if (String.Compare(typeName, "BARREL", true) == 0 ||
                String.Compare(typeName, "BARRELROOF", true) == 0)
            {
                return("BARREL_ROOF");
            }
            if (String.Compare(typeName, "BUTTERFLY", true) == 0 ||
                String.Compare(typeName, "BUTTERFLYROOF", true) == 0)
            {
                return("BUTTERFLY_ROOF");
            }
            if (String.Compare(typeName, "PAVILION", true) == 0 ||
                String.Compare(typeName, "PAVILIONROOF", true) == 0)
            {
                return("PAVILION_ROOF");
            }
            if (String.Compare(typeName, "DOME", true) == 0 ||
                String.Compare(typeName, "DOMEROOF", true) == 0)
            {
                return("DOME_ROOF");
            }

            return(typeName);    //return unchanged. Validation for ENUM will be done later specific to schema version
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Exports a gutter element.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportGutter(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcPipeSegmentType;
            if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

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

                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(setter.LocalPlacement);

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow);
                        IFCAnyHandle        bodyRep             = BodyExporter.ExportBody(exporterIFC, element, categoryId, ElementId.InvalidElementId,
                                                                                          geometryElement, bodyExporterOptions, ecData).RepresentationHnd;
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep))
                        {
                            if (ecData != null)
                            {
                                ecData.ClearOpenings();
                            }
                            return;
                        }
                        string originalTag = NamingUtil.CreateIFCElementId(element);

                        // In Revit, we don't have a corresponding type, so we create one for every gutter.
                        IFCAnyHandle        origin      = ExporterUtil.CreateAxis2Placement3D(file);
                        IFCAnyHandle        repMap3dHnd = IFCInstanceExporter.CreateRepresentationMap(file, origin, bodyRep);
                        List <IFCAnyHandle> repMapList  = new List <IFCAnyHandle>();
                        repMapList.Add(repMap3dHnd);
                        string elementTypeName = NamingUtil.CreateIFCObjectName(exporterIFC, element);

                        string       typeGuid = GUIDUtil.CreateSubElementGUID(element, (int)IFCHostedSweepSubElements.PipeSegmentType);
                        IFCAnyHandle style    = IFCInstanceExporter.CreatePipeSegmentType(file, null, typeGuid,
                                                                                          null, repMapList, IFCPipeSegmentType.Gutter);
                        IFCAnyHandleUtil.OverrideNameAttribute(style, elementTypeName);
                        IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcPipeSegmentType, IFCPipeSegmentType.Gutter.ToString());

                        IFCAnyHandleUtil.SetAttribute(style, "Tag", originalTag);
                        IFCAnyHandleUtil.SetAttribute(style, "ElementType", elementTypeName);

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

                        ISet <IFCAnyHandle> representations = new HashSet <IFCAnyHandle>();
                        representations.Add(mappedItem);

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

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

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

                        IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                        IFCAnyHandle localPlacementToUse;
                        ElementId    roomId = setter.UpdateRoomRelativeCoordinates(element, out localPlacementToUse);
                        if (roomId == ElementId.InvalidElementId)
                        {
                            localPlacementToUse = ecData.GetLocalPlacement();
                        }

                        string guid = GUIDUtil.CreateGUID(element);

                        IFCAnyHandle elemHnd = IFCInstanceExporter.CreateFlowSegment(exporterIFC, element, guid,
                                                                                     ExporterCacheManager.OwnerHistoryHandle, localPlacementToUse, prodRep);

                        bool containedInSpace = (roomId != ElementId.InvalidElementId);
                        productWrapper.AddElement(element, elemHnd, setter.LevelInfo, ecData, !containedInSpace, exportInfo);

                        if (containedInSpace)
                        {
                            ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, elemHnd);
                        }

                        // Associate segment with type.
                        ExporterCacheManager.TypeRelationsCache.Add(style, elemHnd);

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

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

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

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

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

                        SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geomElem);
                        IList <Solid>         solids        = solidMeshInfo.GetSolids();
                        IList <Mesh>          meshes        = solidMeshInfo.GetMeshes();

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

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

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

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

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

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

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

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

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

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

                        IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;

                        string instanceGUID        = GUIDUtil.CreateGUID(element);
                        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));

                        string railingType = IFCValidateEntry.GetValidIFCType(element, ifcEnumType);

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

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

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

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

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

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

                            ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(hostId, stairRampInfo);
                        }
                    }
                    transaction.Commit();
                }
            }
        }
Ejemplo n.º 20
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="exportType">The export type of the element.
        /// <param name="ifcEnumType">The sub-type of the element.</param></param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>True if an entity was created, false otherwise.</returns>
        public static bool Export(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement,
                                  IFCExportType exportType, string ifcEnumType, ProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element, null, null, ExporterUtil.GetBaseLevelIdForElement(element)))
                {
                    IFCAnyHandle localPlacementToUse = setter.GetPlacement();
                    using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                    {
                        extraParams.SetLocalPlacement(localPlacementToUse);

                        ElementId catId = CategoryUtil.GetSafeCategoryId(element);

                        BodyExporterOptions bodyExporterOptions   = new BodyExporterOptions(true);
                        BodyData            bodyData              = null;
                        IFCAnyHandle        productRepresentation = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC,
                                                                                                                               element, catId, geometryElement, bodyExporterOptions, null, extraParams, out bodyData);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(productRepresentation))
                        {
                            extraParams.ClearOpenings();
                            return(false);
                        }

                        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            = GUIDUtil.CreateGUID(type);
                            string typeName            = NamingUtil.GetNameOverride(type, NamingUtil.GetIFCName(type));
                            string typeObjectType      = NamingUtil.GetObjectTypeOverride(type, NamingUtil.CreateIFCObjectName(exporterIFC, type));
                            string applicableOccurence = NamingUtil.GetOverrideStringValue(type, "IfcApplicableOccurrence", typeObjectType);
                            string typeDescription     = NamingUtil.GetDescriptionOverride(type, null);
                            string typeTag             = NamingUtil.GetTagOverride(type, NamingUtil.CreateIFCElementId(type));
                            string typeElementType     = NamingUtil.GetOverrideStringValue(type, "IfcElementType", typeName);

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

                            IFCAnyHandle styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, ifcEnumType, typeGUID, typeName,
                                                                                            typeDescription, applicableOccurence, null, repMapListOpt, typeTag, typeElementType, element, type);
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
                            {
                                productWrapper.RegisterHandleWithElementType(type, styleHandle, null);

                                currentTypeInfo.Style = styleHandle;
                                ExporterCacheManager.TypeObjectsCache.Register(typeId, false, currentTypeInfo);
                            }
                        }
                        string instanceGUID        = GUIDUtil.CreateGUID(element);
                        string instanceName        = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                        string instanceObjectType  = NamingUtil.GetObjectTypeOverride(element, NamingUtil.CreateIFCObjectName(exporterIFC, element));
                        string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceTag         = NamingUtil.GetTagOverride(element, 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, instanceTag);
                        }
                        else if (FamilyExporterUtil.IsDistributionFlowElementSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateDistributionFlowElement(file, instanceGUID, ownerHistory,
                                                                                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if (FamilyExporterUtil.IsEnergyConversionDeviceSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateEnergyConversionDevice(file, instanceGUID, ownerHistory,
                                                                                              instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if (FamilyExporterUtil.IsFlowFittingSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowFitting(file, instanceGUID, ownerHistory,
                                                                                   instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if (FamilyExporterUtil.IsFlowMovingDeviceSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowMovingDevice(file, instanceGUID, ownerHistory,
                                                                                        instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if (FamilyExporterUtil.IsFlowSegmentSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowSegment(file, instanceGUID, ownerHistory,
                                                                                   instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if (FamilyExporterUtil.IsFlowStorageDeviceSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowStorageDevice(file, instanceGUID, ownerHistory,
                                                                                         instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if (FamilyExporterUtil.IsFlowTerminalSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowTerminal(file, instanceGUID, ownerHistory,
                                                                                    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if (FamilyExporterUtil.IsFlowTreatmentDeviceSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowTreatmentDevice(file, instanceGUID, ownerHistory,
                                                                                           instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }
                        else if (FamilyExporterUtil.IsFlowControllerSubType(exportType))
                        {
                            instanceHandle = IFCInstanceExporter.CreateFlowController(file, instanceGUID, ownerHistory,
                                                                                      instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }

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

                        bool relatedToSpace = (roomId != ElementId.InvalidElementId);
                        productWrapper.AddElement(element, instanceHandle, setter, extraParams, !relatedToSpace);
                        if (relatedToSpace)
                        {
                            exporterIFC.RelateSpatialElement(roomId, instanceHandle);
                        }

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

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

                        if (bodyData != null && bodyData.MaterialIds.Count != 0)
                        {
                            CategoryUtil.CreateMaterialAssociations(exporterIFC, instanceHandle, bodyData.MaterialIds);
                        }

                        ExporterCacheManager.MEPCache.Register(element, instanceHandle);

                        tr.Commit();
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 21
0
        private static void ExportAsMappedItem(ExporterIFC exporterIFC, Element element, IFCFile file, IFCExportInfoPair exportType, string ifcEnumType, IFCExtrusionCreationData extraParams,
                                               PlacementSetter setter, IFCAnyHandle localPlacementToUse, IFCAnyHandle productRepresentation, ProductWrapper productWrapper)
        {
            IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
            ElementId    typeId       = element.GetTypeId();
            ElementType  type         = element.Document.GetElement(typeId) as ElementType;
            IFCAnyHandle styleHandle  = null;

            if (type != null)
            {
                FamilyTypeInfo currentTypeInfo = ExporterCacheManager.FamilySymbolToTypeInfoCache.Find(typeId, false, exportType.ExportType);

                bool found = currentTypeInfo.IsValid();
                if (!found)
                {
                    string typeObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, type);

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

                    styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, ifcEnumType, propertySetsOpt, repMapListOpt, element, type);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
                    {
                        propertySetsOpt = ExporterUtil.ExtractElementTypeProperties(exporterIFC, type, styleHandle);
                        productWrapper.RegisterHandleWithElementType(type, styleHandle, propertySetsOpt);
                        currentTypeInfo.Style = styleHandle;
                        ExporterCacheManager.FamilySymbolToTypeInfoCache.Register(typeId, false, exportType.ExportType, currentTypeInfo);
                    }
                }
                else
                {
                    styleHandle = currentTypeInfo.Style;
                }
            }

            string instanceGUID = GUIDUtil.CreateGUID(element);


            bool roomRelated = !FamilyExporterUtil.IsDistributionFlowElementSubType(exportType);

            ElementId roomId = ElementId.InvalidElementId;

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

            IFCAnyHandle instanceHandle = null;

            // For MEP objects
            //string exportEntityStr = exportType.ToString();
            //Common.Enums.IFCEntityType exportEntity;

            //if (String.Compare(exportEntityStr.Substring(exportEntityStr.Length - 4), "Type", true) == 0)
            //   exportEntityStr = exportEntityStr.Substring(0, (exportEntityStr.Length - 4));
            //if (Enum.TryParse(exportEntityStr, out exportEntity))
            //{
            // For MEP object creation
            instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportType, exporterIFC, element, instanceGUID, ownerHistory,
                                                                        localPlacementToUse, productRepresentation);
            //}

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

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

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

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
            {
                ExporterCacheManager.TypeRelationsCache.Add(styleHandle, instanceHandle);
            }

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

            ExporterCacheManager.MEPCache.Register(element, instanceHandle);

            // add to system export cache
            // SystemExporter.ExportSystem(exporterIFC, element, instanceHandle);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Exports a CeilingAndFloor element to IFC.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="floor">The floor element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportCeilingAndFloorElement(ExporterIFC exporterIFC, CeilingAndFloor floorElement, GeometryElement geometryElement,
                                                        ProductWrapper productWrapper)
        {
            if (geometryElement == null)
            {
                return;
            }

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

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

            IFCFile file = exporterIFC.GetFile();

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

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

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

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

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

                IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;

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

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

                        ElementId catId = CategoryUtil.GetSafeCategoryId(floorElement);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        int numReps = exportParts ? 1 : prodReps.Count;

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

                        case IFCEntityType.IfcCovering:
                            exportType.ValidatedPredefinedType = IFCValidateEntry.GetValidIFCType <IFCCoveringType>(floorElement, ifcEnumType, "FLOORING");
                            break;

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

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

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

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

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

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

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

                            slabHnds.Add(slabHnd);

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

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

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

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

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

                return;
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Exports a gutter element.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void ExportGutter(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

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

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

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

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


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

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

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

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

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

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

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

                    tr.Commit();
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Base implementation to export IFC site object.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="document">The Revit document.  It may be null if element isn't.</param>
        /// <param name="element">The element.  It may be null if document isn't.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        private static void ExportSiteBase(ExporterIFC exporterIFC, Document document, Element element, GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            IFCAnyHandle siteHandle = ExporterCacheManager.SiteHandle;

            int numSiteElements = (!IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle) ? 1 : 0);

            if (element == null && (numSiteElements != 0))
            {
                return;
            }

            Document doc = document;

            if (doc == null)
            {
                if (element != null)
                {
                    doc = element.Document;
                }
                else
                {
                    throw new ArgumentException("Both document and element are null.");
                }
            }

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

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                IFCAnyHandle siteRepresentation = null;
                if (element != null)
                {
                    // It would be possible that they actually represent several different sites with different buildings,
                    // but until we have a concept of a building in Revit, we have to assume 0-1 sites, 1 building.
                    bool appendedToSite     = false;
                    bool exportAsFacetation = !ExporterCacheManager.ExportOptionsCache.ExportAsCoordinationView2;
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle))
                    {
                        IList <IFCAnyHandle> representations = IFCAnyHandleUtil.GetProductRepresentations(siteHandle);
                        if (representations.Count > 0)
                        {
                            IFCAnyHandle bodyRep     = representations[0];
                            IFCAnyHandle boundaryRep = null;
                            if (representations.Count > 1)
                            {
                                boundaryRep = representations[1];
                            }

                            siteRepresentation = RepresentationUtil.CreateSurfaceProductDefinitionShape(exporterIFC, element, geometryElement, true, exportAsFacetation, ref bodyRep, ref boundaryRep);
                            if (representations.Count == 1 && !IFCAnyHandleUtil.IsNullOrHasNoValue(boundaryRep))
                            {
                                // If the first site has no boundaryRep,
                                // we will add the boundaryRep from second site to it.
                                representations.Clear();
                                representations.Add(boundaryRep);
                                IFCAnyHandleUtil.AddProductRepresentations(siteHandle, representations);
                            }
                            appendedToSite = true;
                        }
                    }

                    if (!appendedToSite)
                    {
                        siteRepresentation = RepresentationUtil.CreateSurfaceProductDefinitionShape(exporterIFC, element, geometryElement, true, exportAsFacetation);
                    }
                }

                List <int>      latitude     = new List <int>();
                List <int>      longitude    = new List <int>();
                ProjectLocation projLocation = doc.ActiveProjectLocation;

                IFCAnyHandle relativePlacement = null;
                double       unscaledElevation = 0.0;
                if (projLocation != null)
                {
                    const double scaleToDegrees = 180 / Math.PI;
                    double       latitudeInDeg  = projLocation.SiteLocation.Latitude * scaleToDegrees;
                    double       longitudeInDeg = projLocation.SiteLocation.Longitude * scaleToDegrees;

                    ExporterUtil.GetSafeProjectPositionElevation(doc, out unscaledElevation);

                    int latDeg     = ((int)latitudeInDeg); latitudeInDeg -= latDeg; latitudeInDeg *= 60;
                    int latMin     = ((int)latitudeInDeg); latitudeInDeg -= latMin; latitudeInDeg *= 60;
                    int latSec     = ((int)latitudeInDeg); latitudeInDeg -= latSec; latitudeInDeg *= 1000000;
                    int latFracSec = ((int)latitudeInDeg);
                    latitude.Add(latDeg);
                    latitude.Add(latMin);
                    latitude.Add(latSec);
                    if (!ExporterCacheManager.ExportOptionsCache.ExportAs2x2)
                    {
                        latitude.Add(latFracSec);
                    }

                    int longDeg     = ((int)longitudeInDeg); longitudeInDeg -= longDeg; longitudeInDeg *= 60;
                    int longMin     = ((int)longitudeInDeg); longitudeInDeg -= longMin; longitudeInDeg *= 60;
                    int longSec     = ((int)longitudeInDeg); longitudeInDeg -= longSec; longitudeInDeg *= 1000000;
                    int longFracSec = ((int)longitudeInDeg);
                    longitude.Add(longDeg);
                    longitude.Add(longMin);
                    longitude.Add(longSec);
                    if (!ExporterCacheManager.ExportOptionsCache.ExportAs2x2)
                    {
                        longitude.Add(longFracSec);
                    }

                    ExportOptionsCache.SiteTransformBasis transformBasis = ExporterCacheManager.ExportOptionsCache.SiteTransformation;

                    Transform siteSharedCoordinatesTrf = Transform.Identity;

                    if (transformBasis != ExportOptionsCache.SiteTransformBasis.Internal)
                    {
                        BasePoint basePoint = null;
                        if (transformBasis == ExportOptionsCache.SiteTransformBasis.Project)
                        {
                            basePoint = new FilteredElementCollector(doc).WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_ProjectBasePoint)).First() as BasePoint;
                        }
                        else if (transformBasis == ExportOptionsCache.SiteTransformBasis.Site)
                        {
                            basePoint = new FilteredElementCollector(doc).WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_SharedBasePoint)).First() as BasePoint;
                        }

                        if (basePoint != null)
                        {
                            BoundingBoxXYZ bbox = basePoint.get_BoundingBox(null);
                            XYZ            xyz  = bbox.Min;
                            siteSharedCoordinatesTrf = Transform.CreateTranslation(new XYZ(-xyz.X, -xyz.Y, unscaledElevation - xyz.Z));
                        }
                        else
                        {
                            siteSharedCoordinatesTrf = projLocation.GetTransform().Inverse;
                        }
                    }

                    if (!siteSharedCoordinatesTrf.IsIdentity)
                    {
                        double unscaledSiteElevation = ExporterCacheManager.ExportOptionsCache.IncludeSiteElevation ? 0.0 : unscaledElevation;
                        XYZ    orig = UnitUtil.ScaleLength(siteSharedCoordinatesTrf.Origin - new XYZ(0, 0, unscaledSiteElevation));
                        relativePlacement = ExporterUtil.CreateAxis2Placement3D(file, orig, siteSharedCoordinatesTrf.BasisZ, siteSharedCoordinatesTrf.BasisX);
                    }
                }

                // Get elevation for site.
                double elevation = UnitUtil.ScaleLength(unscaledElevation);

                if (IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement))
                {
                    relativePlacement = ExporterUtil.CreateAxis2Placement3D(file);
                }

                IFCAnyHandle localPlacement = IFCInstanceExporter.CreateLocalPlacement(file, null, relativePlacement);
                IFCAnyHandle ownerHistory   = ExporterCacheManager.OwnerHistoryHandle;
                string       siteObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, element);

                ProjectInfo projectInfo     = doc.ProjectInformation;
                Element     mainSiteElement = (element != null) ? element : projectInfo;

                bool   exportSite          = false;
                string siteGUID            = null;
                string siteName            = null;
                string siteLongName        = null;
                string siteLandTitleNumber = null;
                string siteDescription     = null;

                if (element != null)
                {
                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle))
                    {
                        exportSite = true;

                        // We will use the Project Information site name as the primary name, if it exists.
                        siteGUID = GUIDUtil.CreateSiteGUID(doc, element);

                        siteName        = NamingUtil.GetOverrideStringValue(projectInfo, "SiteName", NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element)));
                        siteDescription = NamingUtil.GetDescriptionOverride(element, null);

                        // Look in site element for "IfcLongName" or project information for either "IfcLongName" or "SiteLongName".
                        siteLongName = NamingUtil.GetLongNameOverride(projectInfo, NamingUtil.GetLongNameOverride(element, null));
                        if (string.IsNullOrWhiteSpace(siteLongName))
                        {
                            siteLongName = NamingUtil.GetOverrideStringValue(projectInfo, "SiteLongName", null);
                        }

                        // Look in site element for "IfcLandTitleNumber" or project information for "SiteLandTitleNumber".
                        siteLandTitleNumber = NamingUtil.GetOverrideStringValue(element, "IfcLandTitleNumber", null);
                        if (string.IsNullOrWhiteSpace(siteLandTitleNumber))
                        {
                            siteLandTitleNumber = NamingUtil.GetOverrideStringValue(projectInfo, "SiteLandTitleNumber", null);
                        }
                    }
                }
                else
                {
                    exportSite = true;

                    siteGUID            = GUIDUtil.CreateProjectLevelGUID(doc, IFCProjectLevelGUIDType.Site);
                    siteName            = NamingUtil.GetOverrideStringValue(projectInfo, "SiteName", "Default");
                    siteLongName        = NamingUtil.GetLongNameOverride(projectInfo, NamingUtil.GetOverrideStringValue(projectInfo, "SiteLongName", null));
                    siteLandTitleNumber = NamingUtil.GetOverrideStringValue(projectInfo, "SiteLandTitleNumber", null);

                    // don't bother if we have nothing in the site whatsoever.
                    if ((latitude.Count == 0 || longitude.Count == 0) && IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement) &&
                        string.IsNullOrWhiteSpace(siteLongName) && string.IsNullOrWhiteSpace(siteLandTitleNumber))
                    {
                        return;
                    }
                }

                COBieProjectInfo cobieProjectInfo = ExporterCacheManager.ExportOptionsCache.COBieProjectInfo;
                // Override Site information when it is a special COBie export
                if (ExporterCacheManager.ExportOptionsCache.ExportAs2x3COBIE24DesignDeliverable && cobieProjectInfo != null)
                {
                    siteName        = cobieProjectInfo.SiteLocation;
                    siteDescription = cobieProjectInfo.SiteDescription;
                }

                if (exportSite)
                {
                    siteHandle = IFCInstanceExporter.CreateSite(exporterIFC, element, siteGUID, ownerHistory, siteName, siteDescription, localPlacement,
                                                                siteRepresentation, siteLongName, IFCElementComposition.Element, latitude, longitude, elevation, siteLandTitleNumber, null);
                    productWrapper.AddSite(mainSiteElement, siteHandle);
                    ExporterCacheManager.SiteHandle = siteHandle;
                }


                tr.Commit();
            }
        }
        public override void ExecuteCmdlet()
        {
            CloudFileDirectory baseDirectory;

            switch (this.ParameterSetName)
            {
            case Constants.DirectoryParameterSetName:
                baseDirectory = this.Directory;
                break;

            case Constants.ShareNameParameterSetName:
                baseDirectory = this.BuildFileShareObjectFromName(this.ShareName).GetRootDirectoryReference();
                break;

            case Constants.ShareParameterSetName:
                baseDirectory = this.Share.GetRootDirectoryReference();
                break;

            default:
                throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", this.ParameterSetName));
            }

            if (string.IsNullOrEmpty(this.Path))
            {
                this.RunTask(async(taskId) =>
                {
                    await this.Channel.EnumerateFilesAndDirectoriesAsync(
                        baseDirectory,
                        item => this.WriteListFileItemObject(taskId, this.Channel, item),
                        this.RequestOptions,
                        this.OperationContext,
                        this.CmdletCancellationToken).ConfigureAwait(false);
                });
            }
            else
            {
                this.RunTask(async(taskId) =>
                {
                    bool foundAFolder            = true;
                    string[] subfolders          = NamingUtil.ValidatePath(this.Path);
                    CloudFileDirectory targetDir = baseDirectory.GetDirectoryReferenceByPath(subfolders);

                    try
                    {
                        await this.Channel.FetchDirectoryAttributesAsync(
                            targetDir,
                            null,
                            this.RequestOptions,
                            this.OperationContext,
                            this.CmdletCancellationToken).ConfigureAwait(false);
                    }
                    catch (StorageException se)
                    {
                        if (null == se.RequestInformation ||
                            (int)HttpStatusCode.NotFound != se.RequestInformation.HttpStatusCode)
                        {
                            throw;
                        }

                        foundAFolder = false;
                    }

                    if (foundAFolder)
                    {
                        WriteCloudFileDirectoryeObject(taskId, this.Channel, targetDir);
                        return;
                    }

                    string[] filePath    = NamingUtil.ValidatePath(this.Path, true);
                    CloudFile targetFile = baseDirectory.GetFileReferenceByPath(filePath);

                    await this.Channel.FetchFileAttributesAsync(
                        targetFile,
                        null,
                        this.RequestOptions,
                        this.OperationContext,
                        this.CmdletCancellationToken).ConfigureAwait(false);

                    WriteCloudFileObject(taskId, this.Channel, targetFile);
                });
            }
        }
Ejemplo n.º 26
0
        public override void ExecuteCmdlet()
        {
            CloudFile fileToBeDownloaded;

            string[] path = NamingUtil.ValidatePath(this.Path, true);
            switch (this.ParameterSetName)
            {
            case LocalConstants.FileParameterSetName:
                fileToBeDownloaded = this.File;
                break;

            case LocalConstants.ShareNameParameterSetName:
                var share = this.BuildFileShareObjectFromName(this.ShareName);
                fileToBeDownloaded = share.GetRootDirectoryReference().GetFileReferenceByPath(path);
                break;

            case LocalConstants.ShareParameterSetName:
                fileToBeDownloaded = this.Share.GetRootDirectoryReference().GetFileReferenceByPath(path);
                break;

            case LocalConstants.DirectoryParameterSetName:
                fileToBeDownloaded = this.Directory.GetFileReferenceByPath(path);
                break;

            default:
                throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", this.ParameterSetName));
            }

            string resolvedDestination = this.GetUnresolvedProviderPathFromPSPath(
                string.IsNullOrWhiteSpace(this.Destination) ? "." : this.Destination);

            FileMode mode = this.Force ? FileMode.Create : FileMode.CreateNew;
            string   targetFile;

            if (LocalDirectory.Exists(resolvedDestination))
            {
                // If the destination pointed to an existing directory, we
                // would download the file into the folder with the same name
                // on cloud.
                targetFile = LocalPath.Combine(resolvedDestination, fileToBeDownloaded.GetBaseName());
            }
            else
            {
                // Otherwise we treat the destination as a file no matter if
                // there's one existing or not. The overwrite behavior is configured
                // by FileMode.
                targetFile = resolvedDestination;
            }

            if (ShouldProcess(targetFile, "Download"))
            {
                this.RunTask(async taskId =>
                {
                    await
                    fileToBeDownloaded.FetchAttributesAsync(null, this.RequestOptions, OperationContext,
                                                            CmdletCancellationToken).ConfigureAwait(false);

                    var progressRecord = new ProgressRecord(
                        this.OutputStream.GetProgressId(taskId),
                        string.Format(CultureInfo.CurrentCulture, Resources.ReceiveAzureFileActivity,
                                      fileToBeDownloaded.GetFullPath(), targetFile),
                        Resources.PrepareDownloadingFile);

                    await DataMovementTransferHelper.DoTransfer(() =>
                    {
                        return(this.TransferManager.DownloadAsync(
                                   fileToBeDownloaded,
                                   targetFile,
                                   new DownloadOptions
                        {
                            DisableContentMD5Validation = !this.CheckMd5
                        },
                                   this.GetTransferContext(progressRecord, fileToBeDownloaded.Properties.Length),
                                   CmdletCancellationToken));
                    },
                                                                progressRecord,
                                                                this.OutputStream).ConfigureAwait(false);

                    if (this.PassThru)
                    {
                        this.OutputStream.WriteObject(taskId, fileToBeDownloaded);
                    }
                });
            }
        }
Ejemplo n.º 27
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 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);
            }

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

            IFCFile file = exporterIFC.GetFile();

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

                        ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow);
                        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    = ExporterCacheManager.OwnerHistoryHandle;
                        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, "Insulation");
                        ExporterCacheManager.ElementToHandleCache.Register(element.Id, insulation);

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

                        ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, exporterIFC, element);
                        CategoryUtil.CreateMaterialAssociation(exporterIFC, insulation, matId);
                    }
                }
                tr.Commit();
                return(true);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Exports a Rebar to IFC ReinforcingMesh.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="element">
        /// The element to be exported.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportRebar(ExporterIFC exporterIFC,
                                       Rebar element, Autodesk.Revit.DB.View filterView, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

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

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

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

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

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

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

                        double scale = exporterIFC.LinearScale;

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

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

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

                        string       steelGradeOpt = null;
                        IFCAnyHandle elemHnd       = null;

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

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

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

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

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

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

                        PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper);
                    }
                }
                transaction.Commit();
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Create the "Body" IfcRepresentation for a beam if it is representable by an extrusion, possibly with clippings and openings.
        /// </summary>
        /// <param name="exporterIFC">The exporterIFC class.</param>
        /// <param name="element">The beam element.T</param>
        /// <param name="catId">The category id.</param>
        /// <param name="geomObjects">The list of solids and meshes representing the beam's geometry.
        /// <param name="axisInfo">The beam axis information.</param>
        /// <returns>The BeamBodyAsExtrusionInfo class which contains the created handle (if any) and other information, or null.</returns>
        private static BeamBodyAsExtrusionInfo CreateBeamGeometryAsExtrusion(ExporterIFC exporterIFC, Element element, ElementId catId,
                                                                             IList <GeometryObject> geomObjects, BeamAxisInfo axisInfo)
        {
            // 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 (geomObjects == null || geomObjects.Count != 1 || (!(geomObjects[0] is Solid)) || axisInfo == null || !(axisInfo.Axis is Line))
            {
                return(null);
            }

            BeamBodyAsExtrusionInfo info = new BeamBodyAsExtrusionInfo();

            info.DontExport = false;
            info.Materials  = new HashSet <ElementId>();
            info.Slope      = 0.0;

            Transform orientTrf = axisInfo.LCSAsTransform;

            Solid solid = geomObjects[0] as Solid;

            bool completelyClipped;
            XYZ  beamDirection = orientTrf.BasisX;
            XYZ  planeXVec     = orientTrf.BasisY.Normalize();
            XYZ  planeYVec     = orientTrf.BasisZ.Normalize();

            MaterialAndProfile materialAndProfile = null;
            FootPrintInfo      footPrintInfo      = null;

            string profileName = NamingUtil.GetProfileName(element);

            Plane beamExtrusionBasePlane = GeometryUtil.CreatePlaneByXYVectorsAtOrigin(planeXVec, planeYVec);

            info.RepresentationHandle = ExtrusionExporter.CreateExtrusionWithClipping(exporterIFC, element,
                                                                                      catId, solid, beamExtrusionBasePlane, orientTrf.Origin, beamDirection, null, out completelyClipped,
                                                                                      out footPrintInfo, out materialAndProfile, addInfo: GenerateAdditionalInfo.GenerateProfileDef,
                                                                                      profileName: profileName);
            if (completelyClipped)
            {
                info.DontExport = true;
                return(null);
            }

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(info.RepresentationHandle))
            {
                // 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;
                info.Slope = GeometryUtil.GetSimpleExtrusionSlope(beamDirection, bestAxis);
                ElementId materialId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(solid, exporterIFC, element);
                if (materialId != ElementId.InvalidElementId)
                {
                    info.Materials.Add(materialId);
                }
            }

            if (materialAndProfile != null)
            {
                info.materialAndProfile = materialAndProfile;
            }

            return(info);
        }
Ejemplo n.º 30
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 ProductWrapper.</param>
        /// <returns>True if exported successfully, false otherwise.</returns>
        public static bool ExportDuctLining(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 (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, element))
                {
                    using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                    {
                        ecData.SetLocalPlacement(placementSetter.LocalPlacement);

                        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 ductLining = IFCInstanceExporter.CreateCovering(file, guid,
                                                                                     ownerHistory, name, description, objectType, localPlacement, representation, elementTag, "Wrapping");
                        ExporterCacheManager.ElementToHandleCache.Register(element.Id, ductLining);

                        productWrapper.AddElement(element, ductLining, placementSetter.LevelInfo, ecData, true);

                        ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, exporterIFC, element);
                        CategoryUtil.CreateMaterialAssociation(exporterIFC, ductLining, matId);
                    }
                }
                tr.Commit();
                return(true);
            }
        }