Ejemplo n.º 1
0
        private static bool ExportCustomFabricSheet(FabricSheetExportConfig cfg)
        {
            if (cfg.Equals(null) || cfg.Sheet.IsBent)
            {
                return(false);
            }

            string                 guid         = GUIDUtil.CreateGUID(cfg.Sheet);
            IFCAnyHandle           ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
            HashSet <IFCAnyHandle> rebarHandles = new HashSet <IFCAnyHandle>();
            string                 matName      = NamingUtil.GetMaterialName(cfg.Doc, cfg.MaterialId);

            int ii = 0;

            do
            {
                WireDistributionDirection dir             = (WireDistributionDirection)ii;
                IList <Curve>             wireCenterlines = cfg.Sheet.GetWireCenterlines(dir);
                for (int jj = 0; jj < wireCenterlines.Count; jj++)
                {
                    double wireDiam = 0.0;

                    FabricWireItem wire = cfg.SheetType.GetWireItem(jj, dir);
                    if (cfg.Doc.GetElement(wire.WireType) is FabricWireType wireType)
                    {
                        wireDiam = UnitUtil.ScaleLength(wireType.WireDiameter);
                    }

                    IFCAnyHandle bodyItem = GeometryUtil.CreateSweptDiskSolid(cfg.ExporterIFC, cfg.File, wireCenterlines[jj], wireDiam / 2.0, null);
                    RepresentationUtil.CreateStyledItemAndAssign(cfg.File, cfg.Doc, cfg.MaterialId, bodyItem);

                    ISet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle> {
                        bodyItem
                    };
                    IFCAnyHandle shapeRep = null;
                    if (bodyItems.Count > 0)
                    {
                        shapeRep = RepresentationUtil.CreateAdvancedSweptSolidRep(cfg.ExporterIFC, cfg.Sheet, cfg.CategoryId,
                                                                                  cfg.ExporterIFC.Get3DContextHandle("Body"), bodyItems, null);
                    }
                    IList <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>();
                    if (shapeRep != null)
                    {
                        shapeReps.Add(shapeRep);
                    }

                    IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(cfg.File, null, null, shapeReps);
                    IFCAnyHandle handle  = IFCInstanceExporter.CreateReinforcingBar(cfg.ExporterIFC, cfg.Sheet, guid, ExporterCacheManager.OwnerHistoryHandle,
                                                                                    cfg.PlacementSetter.LocalPlacement, prodRep, matName, wireDiam, 0, 0, IFCReinforcingBarRole.NotDefined, null);
                    IFCAnyHandleUtil.SetAttribute(handle, "ObjectType", "Generic");
                    CategoryUtil.CreateMaterialAssociation(cfg.ExporterIFC, handle, cfg.MaterialId);
                    rebarHandles.Add(handle);
                }
                ii++;
            }while (ii < 2);

            IFCAnyHandle assemblyInstanceHnd = IFCInstanceExporter.CreateElementAssembly(cfg.ExporterIFC, cfg.Sheet, guid,
                                                                                         ownerHistory, cfg.PlacementSetter.LocalPlacement, null, null, IFCElementAssemblyType.UserDefined);
            IFCExportInfoPair assemblyExportInfo = new IFCExportInfoPair(IFCEntityType.IfcElementAssembly);

            cfg.ProductWrapper.AddElement(cfg.Sheet, assemblyInstanceHnd, cfg.PlacementSetter.LevelInfo, null, true, assemblyExportInfo);
            ExporterCacheManager.AssemblyInstanceCache.RegisterAssemblyInstance(cfg.Sheet.Id, assemblyInstanceHnd);
            IFCInstanceExporter.CreateRelAggregates(cfg.File, guid, ownerHistory, null, null, assemblyInstanceHnd, rebarHandles);

            return(true);
        }
Ejemplo n.º 2
0
        private static bool ExportStandardFabricSheet(FabricSheetExportConfig cfg)
        {
            if (cfg.Equals(null))
            {
                return(false);
            }

            string       guid         = GUIDUtil.CreateGUID(cfg.Sheet);
            IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;

            int ii = 0;

            do
            {
                WireDistributionDirection dir             = (WireDistributionDirection)ii;
                IList <Curve>             wireCenterlines = cfg.Sheet?.GetWireCenterlines(dir);
                for (int jj = 0; jj < wireCenterlines.Count; jj++)
                {
                    double wireDiam = 0.0;

                    Element wireTypeElem = (dir == WireDistributionDirection.Major) ? cfg.Doc?.GetElement(cfg.SheetType?.MajorDirectionWireType) :
                                           cfg.Doc?.GetElement(cfg.SheetType?.MinorDirectionWireType);

                    if (wireTypeElem is FabricWireType wireType)
                    {
                        wireDiam = UnitUtil.ScaleLength(wireType.WireDiameter);
                    }
                    IFCAnyHandle bodyItem = GeometryUtil.CreateSweptDiskSolid(cfg.ExporterIFC, cfg.File, wireCenterlines[jj], wireDiam / 2.0, null);

                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(bodyItem))
                    {
                        cfg.BodyItems?.Add(bodyItem);
                        RepresentationUtil.CreateStyledItemAndAssign(cfg.File, cfg.Doc, cfg.MaterialId, bodyItem);
                    }
                }
                ii++;
            }while (ii < 2);

            IFCAnyHandle shapeRep = null;

            if (cfg.BodyItems.Count > 0)
            {
                shapeRep = RepresentationUtil.CreateAdvancedSweptSolidRep(cfg.ExporterIFC, cfg.Sheet, cfg.CategoryId,
                                                                          cfg.ExporterIFC.Get3DContextHandle("Body"), cfg.BodyItems, null);
            }

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

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

            IFCAnyHandle prodRep = (shapeReps != null) ? IFCInstanceExporter.CreateProductDefinitionShape(cfg.File, null, null, shapeReps) : null;

            FabricParams fabricParams = null;

            if (!ExporterCacheManager.FabricParamsCache.TryGetValue(cfg.Sheet.Id, out fabricParams))
            {
                fabricParams = new FabricParams(cfg.Sheet);
                ExporterCacheManager.FabricParamsCache[cfg.Sheet.Id] = fabricParams;
            }

            IFCAnyHandle handle = IFCInstanceExporter.CreateReinforcingMesh(cfg.ExporterIFC, cfg.Sheet, guid, ownerHistory, cfg.EcData.GetLocalPlacement(),
                                                                            prodRep, fabricParams.SteelGrade, fabricParams.MeshLength, fabricParams.MeshWidth,
                                                                            fabricParams.LongitudinalBarNominalDiameter, fabricParams.TransverseBarNominalDiameter,
                                                                            fabricParams.LongitudinalBarCrossSectionArea, fabricParams.TransverseBarCrossSectionArea,
                                                                            fabricParams.LongitudinalBarSpacing, fabricParams.TransverseBarSpacing);
            IFCExportInfoPair exportInfo   = new IFCExportInfoPair(IFCEntityType.IfcReinforcingMesh);
            ElementId         fabricAreaId = cfg.Sheet?.FabricAreaOwnerId;

            if (fabricAreaId != ElementId.InvalidElementId)
            {
                if (!ExporterCacheManager.FabricAreaHandleCache.TryGetValue(fabricAreaId, out HashSet <IFCAnyHandle> fabricSheets))
                {
                    fabricSheets = new HashSet <IFCAnyHandle>();
                    ExporterCacheManager.FabricAreaHandleCache[fabricAreaId] = fabricSheets;
                }
                fabricSheets.Add(handle);
            }
            cfg.ProductWrapper.AddElement(cfg.Sheet, handle, cfg.PlacementSetter?.LevelInfo, cfg.EcData, true, exportInfo);
            CategoryUtil.CreateMaterialAssociation(cfg.ExporterIFC, handle, cfg.MaterialId);

            return(true);
        }
Ejemplo n.º 3
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, MultiplanarOption.IncludeAllMultiplanarCurves);

                    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.IncludeAllMultiplanarCurves, 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;
                            if (!elementName.Contains(shapeName))
                            {
                                // this means that our rebar is a free form bent with varying shapes. We want to have in its name "Shape xx"
                                shapeName = Resources.Shape + " " + shapeName; // This is something like - "Shape 00" or "Shape 17"
                                string formatedString = elementName + " : " + shapeName;
                                rebarNameFormated = origRebarName.Replace(elementName, formatedString);
                            }
                        }

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

                        // For IFC4 and Structural Exchange Requirement export, Entity type not allowed for RV: IfcPolyline
                        IFCAnyHandle           compositeCurve = GeometryUtil.CreateCompositeOrIndexedCurve(exporterIFC, curves, null, null);
                        IFCAnyHandle           sweptDiskSolid = IFCInstanceExporter.CreateSweptDiskSolid(file, compositeCurve, radius, null, 0, endParam);
                        HashSet <IFCAnyHandle> bodyItems      = new HashSet <IFCAnyHandle>();
                        bodyItems.Add(sweptDiskSolid);
                        RepresentationUtil.CreateStyledItemAndAssign(file, rebarElement.Document, materialId, 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);
                        IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcReinforcingBar);

                        // 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, exportInfo));

                        CacheSubelementParameterValues(rebarElement, rebarElementParams, ii, elemHnd);

                        ExporterCacheManager.HandleToElementCache.Register(elemHnd, rebarElement.Id);
                        CategoryUtil.CreateMaterialAssociation(exporterIFC, elemHnd, materialId);
                    }
                }
                transaction.Commit();
            }
            return(createdRebars);
        }