コード例 #1
0
ファイル: OpeningUtil.cs プロジェクト: xinhuaibuhui/revit-ifc
        /// <summary>
        /// Creates openings if there is necessary.
        /// </summary>
        /// <param name="elementHandle">The element handle to create openings.</param>
        /// <param name="element">The element to create openings.</param>
        /// <param name="info">The extrusion data.</param>
        /// <param name="extraParams">The extrusion creation data.</param>
        /// <param name="offsetTransform">The offset transform from ExportBody, or the identity transform.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="originalPlacement">The original placement handle.</param>
        /// <param name="setter">The PlacementSetter.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        private static void CreateOpeningsIfNecessaryBase(IFCAnyHandle elementHandle, Element element, IList<IFCExtrusionData> info,
            IFCExtrusionCreationData extraParams, Transform offsetTransform, ExporterIFC exporterIFC,
            IFCAnyHandle originalPlacement, PlacementSetter setter, ProductWrapper wrapper)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(elementHandle))
            return;

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

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

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

            string openingObjectType = "Opening";

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

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

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

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

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

               IFCAnyHandle openingPlacement = ExporterUtil.CopyLocalPlacement(file, originalPlacement);
               string guid = GUIDUtil.CreateGUID();
               IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
               string openingName = NamingUtil.GetIFCNamePlusIndex(element, openingNumber++);
               IFCAnyHandle openingElement = IFCInstanceExporter.CreateOpeningElement(exporterIFC, element, guid, ownerHistory,
                  openingPlacement, openingRep);
               IFCAnyHandleUtil.OverrideNameAttribute(openingElement, openingName);
               IFCAnyHandleUtil.SetAttribute(openingElement, "ObjectType", openingObjectType);
               IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcOpeningElement);
               wrapper.AddElement(null, openingElement, setter, extraParams, true, exportInfo);
               if (ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities && (extraParams != null))
                  PropertyUtil.CreateOpeningQuantities(exporterIFC, openingElement, extraParams);

               string voidGuid = GUIDUtil.CreateGUID();
               IFCInstanceExporter.CreateRelVoidsElement(file, voidGuid, ownerHistory, null, null, elementHandle, openingElement);
            }
             }
        }
コード例 #2
0
ファイル: OpeningUtil.cs プロジェクト: xinhuaibuhui/revit-ifc
        /// <summary>
        /// Creates openings associated with an extrusion, if there are any.
        /// </summary>
        /// <param name="elementHandle">The element handle to create openings.</param>
        /// <param name="element">The element to create openings.</param>
        /// <param name="extraParams">The extrusion creation data.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="originalPlacement">The original placement handle.</param>
        /// <param name="setter">The PlacementSetter.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        public static void CreateOpeningsIfNecessary(IFCAnyHandle elementHandle, Element element, IFCExtrusionCreationData extraParams,
            Transform offsetTransform, ExporterIFC exporterIFC, IFCAnyHandle originalPlacement,
            PlacementSetter setter, ProductWrapper wrapper)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(elementHandle))
            return;

             ElementId categoryId = CategoryUtil.GetSafeCategoryId(element);

             IList<IFCExtrusionData> info = extraParams.GetOpenings();
             CreateOpeningsIfNecessaryBase(elementHandle, element, info, extraParams, offsetTransform, exporterIFC, originalPlacement, setter, wrapper);
             extraParams.ClearOpenings();
        }
コード例 #3
0
        /// <summary>
        /// Creates an opening from extrusion data.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="hostObjHnd">The host handle.</param>
        /// <param name="hostPlacement">The host placement.</param>
        /// <param name="hostElement">The host element.</param>
        /// <param name="insertElement">The opening element.</param>
        /// <param name="openingGUID">The opening GUID.</param>
        /// <param name="extrusionData">The extrusion data.</param>
        /// <param name="plane">The plane.</param>
        /// <param name="isRecess">True if it is a recess.</param>
        /// <returns>The opening handle.</returns>
        static public IFCAnyHandle CreateOpening(ExporterIFC exporterIFC, IFCAnyHandle hostObjHnd, IFCAnyHandle hostPlacement, Element hostElement,
                                                 Element insertElement, string openingGUID, IFCExtrusionData extrusionData, Plane plane, bool isRecess,
                                                 PlacementSetter setter, ProductWrapper localWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            IList <CurveLoop> curveLoops = extrusionData.GetLoops();

            if (curveLoops.Count == 0)
            {
                return(null);
            }

            if (plane == null)
            {
                // assumption: first curve loop defines the plane.
                if (!curveLoops[0].HasPlane())
                {
                    return(null);
                }
                plane = curveLoops[0].GetPlane();
            }

            ElementId catId = CategoryUtil.GetSafeCategoryId(insertElement);

            IFCAnyHandle openingProdRepHnd = RepresentationUtil.CreateExtrudedProductDefShape(exporterIFC, insertElement, catId,
                                                                                              curveLoops, plane, extrusionData.ExtrusionDirection, extrusionData.ScaledExtrusionLength);

            string       openingObjectType = isRecess ? "Recess" : "Opening";
            IFCAnyHandle ownerHistory      = exporterIFC.GetOwnerHistoryHandle();
            string       openingName       = NamingUtil.GetNameOverride(insertElement, null);

            if (string.IsNullOrEmpty(openingName))
            {
                openingName = NamingUtil.GetNameOverride(hostElement, NamingUtil.CreateIFCObjectName(exporterIFC, hostElement));
            }
            IFCAnyHandle openingHnd = IFCInstanceExporter.CreateOpeningElement(file, openingGUID, ownerHistory, openingName, null,
                                                                               openingObjectType, ExporterUtil.CreateLocalPlacement(file, hostPlacement, null), openingProdRepHnd, null);
            IFCExtrusionCreationData ecData = null;

            if (ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities)
            {
                double height, width;
                ecData = new IFCExtrusionCreationData();
                if (GeometryUtil.ComputeHeightWidthOfCurveLoop(curveLoops[0], plane, out height, out width))
                {
                    ecData.ScaledHeight = UnitUtil.ScaleLength(height);
                    ecData.ScaledWidth  = UnitUtil.ScaleLength(width);
                }
                else
                {
                    double area = ExporterIFCUtils.ComputeAreaOfCurveLoops(curveLoops);
                    ecData.ScaledArea = UnitUtil.ScaleArea(area);
                }
                PropertyUtil.CreateOpeningQuantities(exporterIFC, openingHnd, ecData);
            }

            if (localWrapper != null)
            {
                Element elementForProperties = null;
                if (GUIDUtil.IsGUIDFor(insertElement, openingGUID))
                {
                    elementForProperties = insertElement;
                }

                localWrapper.AddElement(elementForProperties, openingHnd, setter, ecData, true);
            }

            string voidGuid = GUIDUtil.CreateGUID();

            IFCInstanceExporter.CreateRelVoidsElement(file, voidGuid, ownerHistory, null, null, hostObjHnd, openingHnd);
            return(openingHnd);
        }
コード例 #4
0
        /// <summary>
        /// Creates an opening from a solid.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="hostObjHnd">The host object handle.</param>
        /// <param name="hostElement">The host element.</param>
        /// <param name="insertElement">The insert element.</param>
        /// <param name="openingGUID">The GUID for the opening, depending on how the opening is created.</param>
        /// <param name="solid">The solid.</param>
        /// <param name="scaledHostWidth">The scaled host width.</param>
        /// <param name="isRecess">True if it is recess.</param>
        /// <param name="extrusionCreationData">The extrusion creation data.</param>
        /// <param name="setter">The placement setter.</param>
        /// <param name="localWrapper">The product wrapper.</param>
        /// <returns>The created opening handle.</returns>
        static public IFCAnyHandle CreateOpening(ExporterIFC exporterIFC, IFCAnyHandle hostObjHnd, Element hostElement, Element insertElement, string openingGUID,
                                                 Solid solid, double scaledHostWidth, bool isRecess, IFCExtrusionCreationData extrusionCreationData, PlacementSetter setter, ProductWrapper localWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            ElementId catId = CategoryUtil.GetSafeCategoryId(insertElement);

            XYZ  prepToWall;
            bool isLinearWall = GetOpeningDirection(hostElement, out prepToWall);

            if (isLinearWall)
            {
                extrusionCreationData.CustomAxis            = prepToWall;
                extrusionCreationData.PossibleExtrusionAxes = IFCExtrusionAxes.TryCustom;
            }

            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
            BodyData            bodyData            = BodyExporter.ExportBody(exporterIFC, insertElement, catId, ElementId.InvalidElementId,
                                                                              solid, bodyExporterOptions, extrusionCreationData);

            IFCAnyHandle openingRepHnd = bodyData.RepresentationHnd;

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(openingRepHnd))
            {
                extrusionCreationData.ClearOpenings();
                return(null);
            }
            IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();

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

            IFCAnyHandle openingPlacement    = extrusionCreationData.GetLocalPlacement();
            IFCAnyHandle hostObjPlacementHnd = IFCAnyHandleUtil.GetObjectPlacement(hostObjHnd);
            Transform    relTransform        = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(openingPlacement, hostObjPlacementHnd);

            openingPlacement = ExporterUtil.CreateLocalPlacement(file, hostObjPlacementHnd,
                                                                 relTransform.Origin, relTransform.BasisZ, relTransform.BasisX);

            IFCAnyHandle ownerHistory        = exporterIFC.GetOwnerHistoryHandle();
            double       scaledOpeningLength = extrusionCreationData.ScaledLength;
            string       openingObjectType   = "Opening";

            if (!MathUtil.IsAlmostZero(scaledHostWidth) && !MathUtil.IsAlmostZero(scaledOpeningLength))
            {
                openingObjectType = scaledOpeningLength < (scaledHostWidth - MathUtil.Eps()) ? "Recess" : "Opening";
            }
            else
            {
                openingObjectType = isRecess ? "Recess" : "Opening";
            }

            string openingName = NamingUtil.GetNameOverride(insertElement, null);

            if (string.IsNullOrEmpty(openingName))
            {
                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(hostObjHnd))
                {
                    openingName = IFCAnyHandleUtil.GetStringAttribute(hostObjHnd, "Name");
                }
                else
                {
                    openingName = NamingUtil.GetNameOverride(hostElement, NamingUtil.CreateIFCObjectName(exporterIFC, hostElement));
                }
            }

            IFCAnyHandle openingHnd = IFCInstanceExporter.CreateOpeningElement(file, openingGUID, ownerHistory, openingName, null,
                                                                               openingObjectType, openingPlacement, prodRep, null);

            if (ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities)
            {
                PropertyUtil.CreateOpeningQuantities(exporterIFC, openingHnd, extrusionCreationData);
            }

            if (localWrapper != null)
            {
                Element elementForProperties = null;
                if (GUIDUtil.IsGUIDFor(insertElement, openingGUID))
                {
                    elementForProperties = insertElement;
                }

                localWrapper.AddElement(insertElement, openingHnd, setter, extrusionCreationData, true);
            }

            string voidGuid = GUIDUtil.CreateGUID();

            IFCInstanceExporter.CreateRelVoidsElement(file, voidGuid, ownerHistory, null, null, hostObjHnd, openingHnd);
            return(openingHnd);
        }
コード例 #5
0
ファイル: OpeningUtil.cs プロジェクト: masixian/revit-ifc
        /// <summary>
        /// Creates openings if there is necessary.
        /// </summary>
        /// <param name="elementHandle">The element handle to create openings.</param>
        /// <param name="element">The element to create openings.</param>
        /// <param name="info">The extrusion data.</param>
        /// <param name="extraParams">The extrusion creation data.</param>
        /// <param name="offsetTransform">The offset transform from ExportBody, or the identity transform.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="originalPlacement">The original placement handle.</param>
        /// <param name="setter">The PlacementSetter.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        private static void CreateOpeningsIfNecessaryBase(IFCAnyHandle elementHandle, Element element, IList <IFCExtrusionData> info,
                                                          IFCExtrusionCreationData extraParams, Transform offsetTransform, ExporterIFC exporterIFC,
                                                          IFCAnyHandle originalPlacement, PlacementSetter setter, ProductWrapper wrapper)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(elementHandle))
            {
                return;
            }

            int sz = info.Count;

            if (sz == 0)
            {
                return;
            }

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

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

                string openingObjectType = "Opening";

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

                    // Openings shouldn't have surface styles for their geometry.
                    HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>()
                    {
                        extrusionHandle
                    };

                    IFCAnyHandle representationHnd = RepresentationUtil.CreateSweptSolidRep(exporterIFC,
                                                                                            element, categoryId, exporterIFC.Get3DContextHandle("Body"), bodyItems, null);
                    IList <IFCAnyHandle> representations = IFCAnyHandleUtil.IsNullOrHasNoValue(representationHnd) ?
                                                           null : new List <IFCAnyHandle>()
                    {
                        representationHnd
                    };

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

                    IFCAnyHandle openingPlacement = ExporterUtil.CopyLocalPlacement(file, originalPlacement);
                    string       guid             = GUIDUtil.GenerateIFCGuidFrom(IFCEntityType.IfcOpeningElement,
                                                                                 openingNumber.ToString(), elementHandle);
                    IFCAnyHandle ownerHistory       = ExporterCacheManager.OwnerHistoryHandle;
                    string       openingName        = NamingUtil.GetIFCNamePlusIndex(element, openingNumber++);
                    string       openingDescription = NamingUtil.GetDescriptionOverride(element, null);
                    string       openingTag         = NamingUtil.GetTagOverride(element);

                    IFCAnyHandle openingElement = IFCInstanceExporter.CreateOpeningElement(exporterIFC,
                                                                                           guid, ownerHistory, openingName, openingDescription, openingObjectType,
                                                                                           openingPlacement, openingRep, openingTag);
                    IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcOpeningElement);
                    wrapper.AddElement(null, openingElement, setter, extraParams, true, exportInfo);

                    if (ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities && (extraParams != null))
                    {
                        PropertyUtil.CreateOpeningQuantities(exporterIFC, openingElement, extraParams);
                    }

                    string voidGuid = GUIDUtil.GenerateIFCGuidFrom(IFCEntityType.IfcRelVoidsElement,
                                                                   elementHandle, openingElement);
                    IFCInstanceExporter.CreateRelVoidsElement(file, voidGuid, ownerHistory, null, null,
                                                              elementHandle, openingElement);
                }
            }
        }