/// <summary> /// Process to create element quantity. /// </summary> /// <param name="file">The IFC file.</param> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param> /// <param name="element">The element of which this property is created for.</param> /// <param name="elementType">The element type of which this quantity is created for.</param> /// <returns>The created quantity handle.</returns> public IFCAnyHandle ProcessEntry(IFCFile file, ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType, QuantityEntry parentEntry) { bool useProperty = (!String.IsNullOrEmpty(RevitParameterName)) || (RevitBuiltInParameter != BuiltInParameter.INVALID); bool success = false; object val = 0; if (useProperty) { double dblVal = 0.0; if (parentEntry.QuantityType is QuantityType.Count) { int?intValPar = null; intValPar = (ParameterUtil.GetIntValueFromElementOrSymbol(element, RevitParameterName)); if (intValPar.HasValue) { success = true; val = intValPar.Value; } } else { success = (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, RevitParameterName, parentEntry.IgnoreInternalValue, out dblVal) != null); if (!success && RevitBuiltInParameter != BuiltInParameter.INVALID) { success = (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, RevitBuiltInParameter, out dblVal) != null); } if (success) { val = dblVal; } } if (success) // factor in the scale factor for all the parameters depending of the data type to get the correct value { switch (parentEntry.QuantityType) { case QuantityType.PositiveLength: case QuantityType.Length: val = UnitUtil.ScaleLength((double)val); break; case QuantityType.Area: val = UnitUtil.ScaleArea((double)val); break; case QuantityType.Volume: val = UnitUtil.ScaleVolume((double)val); break; case QuantityType.Count: break; case QuantityType.Time: break; default: break; } } } if (PropertyCalculator != null && !success) { success = PropertyCalculator.Calculate(exporterIFC, extrusionCreationData, element, elementType, this); if (success && parentEntry.QuantityType == QuantityType.Count) { val = PropertyCalculator.GetIntValue(); } else { val = PropertyCalculator.GetDoubleValue(); } } IFCAnyHandle quantityHnd = null; if (success) { switch (parentEntry.QuantityType) { case QuantityType.PositiveLength: case QuantityType.Length: quantityHnd = IFCInstanceExporter.CreateQuantityLength(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (double)val); break; case QuantityType.Area: quantityHnd = IFCInstanceExporter.CreateQuantityArea(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (double)val); break; case QuantityType.Volume: quantityHnd = IFCInstanceExporter.CreateQuantityVolume(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (double)val); break; case QuantityType.Weight: quantityHnd = IFCInstanceExporter.CreateQuantityWeight(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (double)val); break; case QuantityType.Count: quantityHnd = IFCInstanceExporter.CreateQuantityCount(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (int)val); break; case QuantityType.Time: quantityHnd = IFCInstanceExporter.CreateQuantityTime(file, parentEntry.PropertyName, parentEntry.MethodOfMeasurement, null, (double)val); break; default: throw new InvalidOperationException("Missing case!"); } } return(quantityHnd); }
/// <summary> /// Exports a generic family instance as IFC instance. /// </summary> /// <param name="type">The export type.</param> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="familyInstance">The element.</param> /// <param name="wrapper">The ProductWrapper.</param> /// <param name="setter">The PlacementSetter.</param> /// <param name="extraParams">The extrusion creation data.</param> /// <param name="instanceGUID">The guid.</param> /// <param name="ownerHistory">The owner history handle.</param> /// <param name="instanceName">The name.</param> /// <param name="instanceDescription">The description.</param> /// <param name="instanceObjectType">The object type.</param> /// <param name="productRepresentation">The representation handle.</param> /// <param name="instanceTag">The tag for the entity, usually based on the element id.</param> /// <param name="ifcEnumType">The predefined type/shape type, if any, for the object.</param> /// <param name="overrideLocalPlacement">The local placement to use instead of the one in the placement setter, if appropriate.</param> /// <returns>The handle.</returns> public static IFCAnyHandle ExportGenericInstance(IFCExportInfoPair type, ExporterIFC exporterIFC, Element familyInstance, ProductWrapper wrapper, PlacementSetter setter, IFCExtrusionCreationData extraParams, string instanceGUID, IFCAnyHandle ownerHistory, IFCAnyHandle productRepresentation, string ifcEnumType, IFCAnyHandle overrideLocalPlacement) { IFCFile file = exporterIFC.GetFile(); Document doc = familyInstance.Document; bool isRoomRelated = IsRoomRelated(type); bool isChildInContainer = familyInstance.AssemblyInstanceId != ElementId.InvalidElementId; IFCAnyHandle localPlacementToUse = setter.LocalPlacement; ElementId roomId = ElementId.InvalidElementId; if (isRoomRelated) { roomId = setter.UpdateRoomRelativeCoordinates(familyInstance, out localPlacementToUse); } //should remove the create method where there is no use of this handle for API methods //some places uses the return value of ExportGenericInstance as input parameter for API methods IFCAnyHandle instanceHandle = null; switch (type.ExportInstance) { case IFCEntityType.IfcBeam: { string preDefinedType = string.IsNullOrWhiteSpace(type.ValidatedPredefinedType) ? "BEAM" : type.ValidatedPredefinedType; instanceHandle = IFCInstanceExporter.CreateBeam(exporterIFC, familyInstance, instanceGUID, ownerHistory, localPlacementToUse, productRepresentation, preDefinedType); break; } case IFCEntityType.IfcColumn: { string preDefinedType = string.IsNullOrWhiteSpace(type.ValidatedPredefinedType) ? "COLUMN" : type.ValidatedPredefinedType; instanceHandle = IFCInstanceExporter.CreateColumn(exporterIFC, familyInstance, instanceGUID, ownerHistory, localPlacementToUse, productRepresentation, preDefinedType); break; } case IFCEntityType.IfcCurtainWall: { instanceHandle = IFCInstanceExporter.CreateCurtainWall(exporterIFC, familyInstance, instanceGUID, ownerHistory, localPlacementToUse, productRepresentation, type.ValidatedPredefinedType); break; } case IFCEntityType.IfcMember: { string preDefinedType = string.IsNullOrWhiteSpace(type.ValidatedPredefinedType) ? "BRACE" : type.ValidatedPredefinedType; instanceHandle = IFCInstanceExporter.CreateMember(exporterIFC, familyInstance, instanceGUID, ownerHistory, localPlacementToUse, productRepresentation, preDefinedType); // Register the members's IFC handle for later use by truss export. ExporterCacheManager.ElementToHandleCache.Register(familyInstance.Id, instanceHandle); break; } case IFCEntityType.IfcPlate: { IFCAnyHandle localPlacement = localPlacementToUse; if (overrideLocalPlacement != null) { isChildInContainer = true; localPlacement = overrideLocalPlacement; } string preDefinedType = string.IsNullOrWhiteSpace(type.ValidatedPredefinedType) ? "NOTDEFINED" : type.ValidatedPredefinedType; instanceHandle = IFCInstanceExporter.CreatePlate(exporterIFC, familyInstance, instanceGUID, ownerHistory, localPlacement, productRepresentation, preDefinedType); break; } case IFCEntityType.IfcMechanicalFastener: { double?nominalDiameter = null; double?nominalLength = null; double nominalDiameterVal, nominalLengthVal; if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalDiameter", out nominalDiameterVal) != null) { nominalDiameter = UnitUtil.ScaleLength(nominalDiameterVal); } if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalLength", out nominalLengthVal) != null) { nominalLength = UnitUtil.ScaleLength(nominalLengthVal); } string preDefinedType = string.IsNullOrWhiteSpace(type.ValidatedPredefinedType) ? "NOTDEFINED" : type.ValidatedPredefinedType; instanceHandle = IFCInstanceExporter.CreateMechanicalFastener(exporterIFC, familyInstance, instanceGUID, ownerHistory, localPlacementToUse, productRepresentation, nominalDiameter, nominalLength, preDefinedType); break; } case IFCEntityType.IfcRailing: { //string strEnumType; //IFCExportInfoPair exportAs = ExporterUtil.GetExportType(exporterIFC, familyInstance, out strEnumType); //if (ExporterCacheManager.ExportOptionsCache.ExportAs4) //{ // instanceHandle = IFCInstanceExporter.CreateRailing(exporterIFC, familyInstance, instanceGUID, ownerHistory, // localPlacementToUse, productRepresentation, GetPreDefinedType<Toolkit.IFC4.IFCRailingType>(familyInstance, strEnumType).ToString()); //} //else //{ // instanceHandle = IFCInstanceExporter.CreateRailing(exporterIFC, familyInstance, instanceGUID, ownerHistory, // localPlacementToUse, productRepresentation, GetPreDefinedType<Toolkit.IFCRailingType>(familyInstance, strEnumType).ToString()); //} string preDefinedType = string.IsNullOrWhiteSpace(type.ValidatedPredefinedType) ? "NOTDEFINED" : type.ValidatedPredefinedType; instanceHandle = IFCInstanceExporter.CreateRailing(exporterIFC, familyInstance, instanceGUID, ownerHistory, localPlacementToUse, productRepresentation, preDefinedType); break; } case IFCEntityType.IfcSpace: { IFCInternalOrExternal internalOrExternal = CategoryUtil.IsElementExternal(familyInstance) ? IFCInternalOrExternal.External : IFCInternalOrExternal.Internal; instanceHandle = IFCInstanceExporter.CreateSpace(exporterIFC, familyInstance, instanceGUID, ownerHistory, localPlacementToUse, productRepresentation, IFCElementComposition.Element, internalOrExternal); break; } default: { // !!! These entities are deprecated in IFC4 and will be made abstract in the next version. // It is still kept as it is because if we generate an IfcBuildingElementProxy, teh connectivity will be lost if (ExporterCacheManager.ExportOptionsCache.ExportAs4 && (type.ExportInstance == IFCEntityType.IfcDistributionElement || type.ExportInstance == IFCEntityType.IfcEnergyConversionDevice || type.ExportInstance == IFCEntityType.IfcFlowController || type.ExportInstance == IFCEntityType.IfcFlowFitting || type.ExportInstance == IFCEntityType.IfcFlowMovingDevice || type.ExportInstance == IFCEntityType.IfcFlowSegment || type.ExportInstance == IFCEntityType.IfcFlowStorageDevice || type.ExportInstance == IFCEntityType.IfcFlowTerminal || type.ExportInstance == IFCEntityType.IfcFlowTreatmentDevice)) { instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(type, exporterIFC, familyInstance, instanceGUID, ownerHistory, localPlacementToUse, productRepresentation); } else { if (type.ExportInstance != IFCEntityType.UnKnown) { instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(type, exporterIFC, familyInstance, instanceGUID, ownerHistory, localPlacementToUse, productRepresentation); } } break; } } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle)) { bool containedInSpace = (roomId != ElementId.InvalidElementId); bool associateToLevel = containedInSpace ? false : !isChildInContainer; wrapper.AddElement(familyInstance, instanceHandle, setter, extraParams, associateToLevel); if (containedInSpace) { ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, instanceHandle); } } return(instanceHandle); }
/// <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; if (Enum.TryParse <Common.Enums.IFCEntityType>("IfcReinforcingBar", out elementClassTypeEnum)) { 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; } } int indexForNamingAndGUID = (itemIndex > 0) ? ii + itemIndex : ii + 1; string rebarName = NamingUtil.GetNameOverride(rebarElement, origRebarName + ": " + 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.SetAttribute(elemHnd, "Name", 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); }
/// <summary> /// Exports a roof to IfcRoof. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="ifcEnumType">The roof type.</param> /// <param name="roof">The roof element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void ExportRoof(ExporterIFC exporterIFC, string ifcEnumType, Element roof, GeometryElement geometryElement, ProductWrapper productWrapper) { if (roof == null || geometryElement == null) { return; } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, roof)) { using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData()) { // If the roof is an in-place family, we will allow any arbitrary orientation. While this may result in some // in-place "cubes" exporting with the wrong direction, it is unlikely that an in-place family would be // used for this reason in the first place. ecData.PossibleExtrusionAxes = (roof is FamilyInstance) ? IFCExtrusionAxes.TryXYZ : IFCExtrusionAxes.TryZ; ecData.AreInnerRegionsOpenings = true; ecData.SetLocalPlacement(placementSetter.LocalPlacement); ElementId categoryId = CategoryUtil.GetSafeCategoryId(roof); BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow); BodyData bodyData; IFCAnyHandle representation = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC, roof, categoryId, geometryElement, bodyExporterOptions, null, ecData, out bodyData); if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation)) { ecData.ClearOpenings(); return; } bool exportSlab = ecData.ScaledLength > MathUtil.Eps(); string guid = GUIDUtil.CreateGUID(roof); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; IFCAnyHandle localPlacement = ecData.GetLocalPlacement(); //string predefinedType = GetIFCRoofType(ifcEnumType); string predefinedType = IFCValidateEntry.GetValidIFCPredefinedTypeType(ifcEnumType, "NOTDEFINED", IFCEntityType.IfcRoofType.ToString()); IFCAnyHandle roofHnd = IFCInstanceExporter.CreateRoof(exporterIFC, roof, guid, ownerHistory, localPlacement, exportSlab ? null : representation, predefinedType); // Export IfcRoofType IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcRoof, IFCEntityType.IfcRoofType, predefinedType); if (exportInfo.ExportType != IFCEntityType.UnKnown) { string overridePDefType; if (ParameterUtil.GetStringValueFromElementOrSymbol(roof, "IfcExportType", out overridePDefType) == null) // change IFCType to consistent parameter of IfcExportType { if (ParameterUtil.GetStringValueFromElementOrSymbol(roof, "IfcType", out overridePDefType) == null) // support IFCType for legacy support { if (string.IsNullOrEmpty(predefinedType)) { predefinedType = "NOTDEFINED"; } } } if (!string.IsNullOrEmpty(overridePDefType)) { exportInfo.ValidatedPredefinedType = overridePDefType; } else { exportInfo.ValidatedPredefinedType = predefinedType; } IFCAnyHandle typeHnd = ExporterUtil.CreateGenericTypeFromElement(roof, exportInfo, file, ownerHistory, predefinedType, productWrapper); ExporterCacheManager.TypeRelationsCache.Add(typeHnd, roofHnd); } productWrapper.AddElement(roof, roofHnd, placementSetter.LevelInfo, ecData, true); // will export its host object materials later if it is a roof if (!(roof is RoofBase)) { CategoryUtil.CreateMaterialAssociation(exporterIFC, roofHnd, bodyData.MaterialIds); } if (exportSlab) { string slabGUID = GUIDUtil.CreateSubElementGUID(roof, (int)IFCRoofSubElements.RoofSlabStart); string slabName = IFCAnyHandleUtil.GetStringAttribute(roofHnd, "Name") + ":1"; IFCAnyHandle slabLocalPlacementHnd = ExporterUtil.CopyLocalPlacement(file, localPlacement); IFCAnyHandle slabHnd = IFCInstanceExporter.CreateSlab(exporterIFC, roof, slabGUID, ownerHistory, slabLocalPlacementHnd, representation, slabRoofPredefinedType); IFCAnyHandleUtil.OverrideNameAttribute(slabHnd, slabName); Transform offsetTransform = (bodyData != null) ? bodyData.OffsetTransform : Transform.Identity; OpeningUtil.CreateOpeningsIfNecessary(slabHnd, roof, ecData, offsetTransform, exporterIFC, slabLocalPlacementHnd, placementSetter, productWrapper); ExporterUtil.RelateObject(exporterIFC, roofHnd, slabHnd); productWrapper.AddElement(null, slabHnd, placementSetter.LevelInfo, ecData, false); CategoryUtil.CreateMaterialAssociation(exporterIFC, slabHnd, bodyData.MaterialIds); // Create type IFCExportInfoPair slabRoofExportType = new IFCExportInfoPair(); slabRoofExportType.SetValueWithPair(IFCEntityType.IfcSlab); IFCAnyHandle slabRoofTypeHnd = ExporterUtil.CreateGenericTypeFromElement(roof, slabRoofExportType, exporterIFC.GetFile(), ownerHistory, slabRoofPredefinedType, productWrapper); ExporterCacheManager.TypeRelationsCache.Add(slabRoofTypeHnd, slabHnd); } } tr.Commit(); } } }
/// <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, null, repMapList, IFCPipeSegmentType.Gutter); IFCAnyHandleUtil.OverrideNameAttribute(style, elementTypeName); IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcPipeSegmentType, IFCPipeSegmentType.Gutter.ToString()); IFCAnyHandleUtil.SetAttribute(style, "Tag", originalTag); ExporterUtil.SetGlobalId(style, typeGuid); 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(); } } }
/// <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, ref GeometryElement geometryElement, ProductWrapper productWrapper) { if (geometryElement == null) { return; } IFCFile file = exporterIFC.GetFile(); string ifcEnumType; IFCExportInfoPair exportType = ExporterUtil.GetProductExportType(exporterIFC, floorElement, out ifcEnumType); IFCAnyHandle type = null; if (!ElementFilteringUtil.IsElementVisible(floorElement)) { 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>(exportType.ExportInstance.ToString(), out elementClassTypeEnum) || Enum.TryParse <Common.Enums.IFCEntityType>(exportType.ExportType.ToString(), out elementClassTypeEnum)) { if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return; } } Document doc = floorElement.Document; using (SubTransaction tempPartTransaction = new SubTransaction(doc)) { MaterialLayerSetInfo layersetInfo = new MaterialLayerSetInfo(exporterIFC, floorElement, productWrapper); // For IFC4RV export, Element will be split into its parts(temporarily) in order to export the wall by its parts // If Parts are created by code and not by user then their names should be equal to Material names. bool setMaterialNameToPartName = ExporterUtil.CreateParts(floorElement, layersetInfo.MaterialIds.Count, ref geometryElement); ExporterUtil.ExportPartAs exportPartAs = ExporterUtil.CanExportByComponentsOrParts(floorElement); bool exportByComponents = exportPartAs == ExporterUtil.ExportPartAs.ShapeAspect; bool exportParts = exportPartAs == ExporterUtil.ExportPartAs.Part; if (exportParts && !PartExporter.CanExportElementInPartExport(floorElement, floorElement.LevelId, false)) { 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, 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()) { // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, floorElement, out overrideContainerHnd); using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, floorElement, null, null, overrideContainerId, overrideContainerHnd)) { 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 && !ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView; 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 (!exportParts) { 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(); IList <GeometryObject> gObjs = FamilyExporterUtil.RemoveInvisibleSolidsAndMeshes(floorElement.Document, exporterIFC, ref solids, ref meshes); if (solids.Count == 1 && meshes.Count == 0) { // 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 = GenerateAdditionalInfo.GenerateBody; additionalInfo |= ExporterCacheManager.ExportOptionsCache.ExportAs4 ? GenerateAdditionalInfo.GenerateFootprint : GenerateAdditionalInfo.None; // Skip generate body item for IFC4RV. It will be handled later in PartExporter.ExportHostPartAsShapeAspects() if (exportByComponents) { additionalInfo &= ~GenerateAdditionalInfo.GenerateBody; } ExtrusionExporter.ExtraClippingData extraClippingData = null; HandleAndData floorAndProperties = ExtrusionExporter.CreateExtrusionWithClippingAndProperties(exporterIFC, floorElement, false, catId, solids[0], extrusionAnalyzerFloorBasePlane, floorOrigin, floorExtrusionDirection, null, out extraClippingData, addInfo: additionalInfo); if (extraClippingData.CompletelyClipped) { return; } IList <IFCAnyHandle> representations = new List <IFCAnyHandle>(); if (floorAndProperties.Handle != null) { representations.Add(floorAndProperties.Handle); repTypes.Add(ShapeRepresentationType.SweptSolid); } // Footprint representation will only be exported in export to IFC4 if (((additionalInfo & GenerateAdditionalInfo.GenerateFootprint) != 0) && (floorAndProperties.FootprintInfo != null)) { IFCAnyHandle footprintShapeRep = floorAndProperties.FootprintInfo.CreateFootprintShapeRepresentation(exporterIFC); representations.Add(footprintShapeRep); } if (exportByComponents) { IFCAnyHandle prodRep = RepresentationUtil.CreateProductDefinitionShapeWithoutBodyRep(exporterIFC, floorElement, catId, geometryElement, representations); prodReps.Add(prodRep); } else if (representations.Count > 0 && floorAndProperties.Handle != null) // Only when at least the body rep exists will come here { IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations); prodReps.Add(prodRep); } if (floorAndProperties.Data != null) { loopExtraParams.Add(floorAndProperties.Data); } } } } // Use internal routine as backup that handles openings. if (prodReps.Count == 0 && canExportAsInternalExtrusion && !exportByComponents) { exportedAsInternalExtrusion = ExporterIFCUtils.ExportSlabAsExtrusion(exporterIFC, floorElement, geometryElement, transformSetter, localPlacement, out localPlacements, out prodReps, out extrusionLoops, out loopExtraParams, floorPlane); PotentiallyFixPresentationLayerAssignment(floorElement, prodReps); 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) { 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); IList <IFCAnyHandle> reps = new List <IFCAnyHandle>(); reps.Add(footprintShapeRepresentation); IFCAnyHandleUtil.AddRepresentations(prodReps[ii], reps); } } } } } IFCAnyHandle prodDefHnd; if (prodReps.Count == 0) { if (exportByComponents) { prodDefHnd = RepresentationUtil.CreateProductDefinitionShapeWithoutBodyRep(exporterIFC, floorElement, catId, geometryElement, null); prodReps.Add(prodDefHnd); } else { 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; 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; // Deal with a couple of cases that have non-standard defaults. switch (exportType.ExportInstance) { case IFCEntityType.IfcCovering: exportType.ValidatedPredefinedType = IFCValidateEntry.GetValidIFCType <IFCCoveringType>(floorElement, ifcEnumType, "FLOORING"); break; case IFCEntityType.IfcSlab: bool isBaseSlab = false; #pragma warning disable CS0612, CS0618//AnalyticalModel is obsolette 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; #pragma warning restore CS0612, CS0618 } 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); } // Pre IFC4 Slab does not have PredefinedType if (!string.IsNullOrEmpty(exportType.ValidatedPredefinedType) && !ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4) { IFCAnyHandleUtil.SetAttribute(slabHnd, "PredefinedType", exportType.ValidatedPredefinedType, true); } if (exportParts) { PartExporter.ExportHostPart(exporterIFC, floorElement, slabHnd, productWrapper, placementSetter, localPlacementHnd, null, setMaterialNameToPartName); } else if (exportByComponents) { IFCExtrusionCreationData partECData = new IFCExtrusionCreationData(); IFCAnyHandle hostShapeRepFromParts = PartExporter.ExportHostPartAsShapeAspects(exporterIFC, floorElement, prodReps[ii], productWrapper, placementSetter, localPlacement, ElementId.InvalidElementId, layersetInfo, partECData); loopExtraParams.Add(partECData); } slabHnds.Add(slabHnd); // For IFC4RV, export of the geometry is already handled in PartExporter.ExportHostPartAsShapeAspects() if (!exportParts && !exportByComponents) { 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, exportType); type = ExporterUtil.CreateGenericTypeFromElement(floorElement, exportType, file, ownerHistory, exportType.ValidatedPredefinedType, productWrapper); ExporterCacheManager.TypeRelationsCache.Add(type, slabHnds[ii]); ExporterUtil.AddIntoComplexPropertyCache(slabHnds[ii], layersetInfo); } // 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) { ISet <IFCAnyHandle> oldCreatedObjects = productWrapper.GetAllObjects(); ExporterIFCUtils.ExportExtrudedSlabOpenings(exporterIFC, floorElement, placementSetter.LevelInfo, localPlacements[0], slabHnds, extrusionLoops, floorPlane, productWrapper.ToNative()); ISet <IFCAnyHandle> newCreatedObjects = productWrapper.GetAllObjects(); newCreatedObjects.ExceptWith(oldCreatedObjects); PotentiallyFixPresentationLayerAssignment(floorElement, newCreatedObjects); } } if (!exportParts) { if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement, productWrapper.GetAnElement(), geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, false, type); } else { 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; } } }
public void Execute() { var array = new List <JProperty> { new JProperty("field", this.ExpressionBuilder.GetFieldName(this.FieldExpression)) }; JProperty domain = null; if (this.Excludes?.Any() ?? false) { var excludeValue = new JObject(new JProperty("excludeTags", new JArray(this.Excludes))); domain = new JProperty("domain", excludeValue); } if (this.Filter != null) { var filter = new JProperty("filter", this.Filter.Execute()); domain = domain ?? new JProperty("domain", new JObject()); ((JObject)domain.Value).Add(filter); } if (domain != null) { array.Add(domain); } if (this.Minimum.HasValue) { array.Add(new JProperty("mincount", this.Minimum.Value)); } if (!string.IsNullOrWhiteSpace(this.Gap)) { array.Add(new JProperty("gap", this.Gap)); } if (!string.IsNullOrWhiteSpace(this.Start)) { array.Add(new JProperty("start", this.Start)); } if (!string.IsNullOrWhiteSpace(this.End)) { array.Add(new JProperty("end", this.End)); } if (this.HardEnd) { array.Add(new JProperty("hardend", true)); } if (this.CountBefore || this.CountAfter) { var content = new List <string>(); if (this.CountBefore) { content.Add("before"); } if (this.CountAfter) { content.Add("after"); } array.Add(new JProperty("other", new JArray(content.ToArray()))); } if (this.SortType.HasValue) { ParameterUtil.GetFacetSort(this.SortType.Value, out string typeName, out string sortName); array.Add(new JProperty("sort", new JObject(new JProperty(typeName, sortName)))); } this._result = new JProperty(this.AliasName, new JObject(new JProperty("range", new JObject(array.ToArray())))); }
/// <summary> /// Calculates span value for a beam. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="extrusionCreationData"> /// The IFCExtrusionCreationData. /// </param> /// <param name="element"> /// The element to calculate the value. /// </param> /// <param name="elementType"> /// The element type. /// </param> /// <returns> /// True if the operation succeed, false otherwise. /// </returns> public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType) { // Check the override first from "IfcSpan" parameter, if not overriden use the geometry data from extrusion double spanVal; if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcSpan", out spanVal) != null) { m_Span = UnitUtil.ScaleLength(spanVal); return(true); } if (extrusionCreationData == null || MathUtil.IsAlmostZero(extrusionCreationData.ScaledLength)) { return(false); } m_Span = extrusionCreationData.ScaledLength; AnalyticalModel elemAnalyticalModel = element.GetAnalyticalModel(); if (elemAnalyticalModel != null) { IList <AnalyticalModelSupport> supports = elemAnalyticalModel.GetAnalyticalModelSupports(); if (supports != null && supports.Count > 0) { if (supports.Count == 2) { AnalyticalSupportType supportType1 = supports[0].GetSupportType(); AnalyticalSupportType supportType2 = supports[1].GetSupportType(); // If there are exactly 2 supports, calculate the distance between the supports for Span (if the type is PointSupport) if (supportType1 == AnalyticalSupportType.PointSupport && supportType2 == AnalyticalSupportType.PointSupport) { XYZ support1 = supports[0].GetPoint(); XYZ support2 = supports[1].GetPoint(); m_Span = UnitUtil.ScaleLength(support1.DistanceTo(support2)); } // CurveSUpport or SurfaceSupport?? else { if (supportType1 == AnalyticalSupportType.PointSupport) { XYZ supportP = supports[0].GetPoint(); if (supportType2 == AnalyticalSupportType.CurveSupport) { Curve supportC = supports[1].GetCurve(); m_Span = UnitUtil.ScaleLength(supportC.Distance(supportP)); } else if (supportType2 == AnalyticalSupportType.SurfaceSupport) { Face supportF = supports[1].GetFace(); m_Span = UnitUtil.ScaleLength(supportF.Project(supportP).Distance); } } else if (supportType1 == AnalyticalSupportType.CurveSupport) { Curve supportC = supports[0].GetCurve(); if (supportType2 == AnalyticalSupportType.PointSupport) { XYZ supportP = supports[1].GetPoint(); m_Span = UnitUtil.ScaleLength(supportC.Distance(supportP)); } else if (supportType2 == AnalyticalSupportType.SurfaceSupport) { Face supportF = supports[1].GetFace(); // TODO, how to calculate a distance from a Curve to a Face? } } else if (supportType1 == AnalyticalSupportType.SurfaceSupport) { Face supportF = supports[0].GetFace(); if (supportType2 == AnalyticalSupportType.PointSupport) { XYZ supportP = supports[1].GetPoint(); m_Span = UnitUtil.ScaleLength(supportF.Project(supportP).Distance); } else if (supportType2 == AnalyticalSupportType.CurveSupport) { Curve supportC = supports[1].GetCurve(); // TODO, how to calculate a distance from a Curve to a Face? } } } } else if (supports.Count > 2) { // If there are more than 2 supports, which Span to take?? } else { // If only one or less support // Otherwise do nothing, leave it to the extrusion length } } else { // No support, do nothing. Leave the Span to be the length of the entire beam } } return(true); }
/// <summary> /// Calculates slope value. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param> /// <param name="element">The element to calculate the value.</param> /// <param name="elementType">The element type.</param> /// <returns>True if the operation succeed, false otherwise.</returns> public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType) { double slope = double.NaN; // We may have an extrusionCreationData that doesn't have anything set. We will check this by seeing if there is a valid length set. // This works for Beam if (extrusionCreationData == null || MathUtil.IsAlmostZero(extrusionCreationData.ScaledLength)) { // Try looking for parameters that we can calculate slope from. double startParamHeight = 0.0; double endParamHeight = 0.0; double length = 0.0; if ((ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION, out startParamHeight) != null) && (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION, out endParamHeight) != null) && (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.INSTANCE_LENGTH_PARAM, out length) != null)) { if (!MathUtil.IsAlmostZero(length)) { double factor = Math.Abs(endParamHeight - startParamHeight) / length; slope = UnitUtil.ScaleAngle(MathUtil.SafeAsin(factor)); if (!double.IsNaN(slope)) { m_Slope = slope; return(true); } } } } // This works for Ramp/RampFlight if (ParameterUtil.GetDoubleValueFromElement(element, BuiltInParameter.RAMP_ATTR_MIN_INV_SLOPE, out slope) != null) { m_Slope = UnitUtil.ScaleAngle(Math.Atan(slope)); return(true); } // For other elements with ExtrusionData. Parameter will take precedence (override) if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "Slope", out slope) != null) { m_Slope = UnitUtil.ScaleAngle(slope); return(true); } if (extrusionCreationData != null) { if (extrusionCreationData.Slope > MathUtil.Eps()) { m_Slope = extrusionCreationData.Slope; return(true); } else { // For any element that has axis, the slope will be computed based on the angle of the line vector if (element.Location != null && element.Location is LocationCurve) { LocationCurve axis = element.Location as LocationCurve; if (axis.Curve is Line) { Line axisCurve = axis.Curve as Line; XYZ vectorProjOnXY = new XYZ(axisCurve.Direction.X, axisCurve.Direction.Y, 0.0).Normalize(); //Project the vector to XY plane if (axisCurve.Direction.GetLength() > 0.0 && vectorProjOnXY.GetLength() > 0.0) { slope = UnitUtil.ScaleAngle(MathUtil.SafeAcos(axisCurve.Direction.DotProduct(vectorProjOnXY) / (axisCurve.Direction.GetLength() * vectorProjOnXY.GetLength()))); } if (!double.IsNaN(slope)) { m_Slope = slope; return(true); } } } } } // The last attempt to compute the slope angle is to get the slope of the largest top facing face of the geometry GeometryElement geomElem = element.get_Geometry(GeometryUtil.GetIFCExportGeometryOptions()); Face largestTopFace = null; if (geomElem == null) { return(false); } foreach (GeometryObject geomObj in geomElem) { largestTopFace = GeometryUtil.GetLargestFaceInSolid(geomObj, new XYZ(0, 0, 1)); } if (largestTopFace != null) { XYZ faceNormal = largestTopFace.ComputeNormal(new UV()); XYZ faceNormalProjXYPlane = new XYZ(faceNormal.X, faceNormal.Y, 0.0).Normalize(); slope = GeometryUtil.GetAngleOfFace(largestTopFace, faceNormalProjXYPlane); if (!double.IsNaN(slope)) { m_Slope = slope; return(true); } } return(false); }
/// <summary> /// Get the handles of Grid Axes. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="sameDirectionAxes">The grid axes in the same direction of one level.</param> /// <param name="representations">The representation of grid axis.</param> /// <returns>The list of handles of grid axes.</returns> private static List <IFCAnyHandle> CreateIFCGridAxisAndRepresentations(ExporterIFC exporterIFC, ProductWrapper productWrapper, IList <Grid> sameDirectionAxes, IList <IFCAnyHandle> representations, GridRepresentationData gridRepresentationData) { if (sameDirectionAxes.Count == 0) { return(null); } IDictionary <ElementId, List <IFCAnyHandle> > gridAxisMap = new Dictionary <ElementId, List <IFCAnyHandle> >(); IDictionary <ElementId, List <IFCAnyHandle> > gridRepMap = new Dictionary <ElementId, List <IFCAnyHandle> >(); IFCFile ifcFile = exporterIFC.GetFile(); Grid baseGrid = sameDirectionAxes[0]; Plane plane = new Plane(XYZ.BasisX, XYZ.BasisY, XYZ.Zero); List <IFCAnyHandle> ifcGridAxes = new List <IFCAnyHandle>(); foreach (Grid grid in sameDirectionAxes) { // Because the IfcGrid is a collection of Revit Grids, any one of them can override the IFC CAD Layer. // We will take the first name, and not do too much checking. if (string.IsNullOrWhiteSpace(gridRepresentationData.m_IFCCADLayer)) { ParameterUtil.GetStringValueFromElementOrSymbol(grid, "IFCCadLayer", out gridRepresentationData.m_IFCCADLayer); } // Get the handle of curve. XYZ projectionDirection = plane.Normal; IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, plane, projectionDirection, false); ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, grid.Curve, XYZ.Zero, false); IList <IFCAnyHandle> curves = info.GetCurves(); if (curves.Count != 1) { throw new Exception("IFC: expected 1 curve when export curve element."); } IFCAnyHandle axisCurve = curves[0]; bool sameSense = true; if (baseGrid.Curve is Line) { Line baseLine = baseGrid.Curve as Line; Line axisLine = grid.Curve as Line; sameSense = (axisLine.Direction.IsAlmostEqualTo(baseLine.Direction)); } IFCAnyHandle ifcGridAxis = IFCInstanceExporter.CreateGridAxis(ifcFile, grid.Name, axisCurve, sameSense); ifcGridAxes.Add(ifcGridAxis); HashSet <IFCAnyHandle> AxisCurves = new HashSet <IFCAnyHandle>(); AxisCurves.Add(axisCurve); IFCAnyHandle repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(ifcFile, AxisCurves); // get the weight and color from the GridType to create the curve style. GridType gridType = grid.Document.GetElement(grid.GetTypeId()) as GridType; IFCData curveWidth = null; if (ExporterCacheManager.ExportOptionsCache.ExportAnnotations) { int outWidth; double width = (ParameterUtil.GetIntValueFromElement(gridType, BuiltInParameter.GRID_END_SEGMENT_WEIGHT, out outWidth) != null) ? outWidth : 1; curveWidth = IFCDataUtil.CreateAsPositiveLengthMeasure(width); } int outColor; int color = (ParameterUtil.GetIntValueFromElement(gridType, BuiltInParameter.GRID_END_SEGMENT_COLOR, out outColor) != null) ? outColor : 0; double blueVal = 0.0; double greenVal = 0.0; double redVal = 0.0; GeometryUtil.GetRGBFromIntValue(color, out blueVal, out greenVal, out redVal); IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(ifcFile, null, redVal, greenVal, blueVal); BodyExporter.CreateCurveStyleForRepItem(exporterIFC, repItemHnd, curveWidth, colorHnd); HashSet <IFCAnyHandle> curveSet = new HashSet <IFCAnyHandle>(); curveSet.Add(repItemHnd); gridRepresentationData.m_Grids.Add(grid); gridRepresentationData.m_curveSets.Add(curveSet); } return(ifcGridAxes); }
/// <summary> /// Exports an element as IFC covering. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="element">The element to be exported.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void ExportCovering(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, string ifcEnumType, ProductWrapper productWrapper) { bool exportParts = PartExporter.CanExportParts(element); if (exportParts && !PartExporter.CanExportElementInPartExport(element, element.LevelId, false)) { 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.IfcCovering; if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return; } ElementType elemType = element.Document.GetElement(element.GetTypeId()) as ElementType; IFCFile file = exporterIFC.GetFile(); MaterialLayerSetInfo layersetInfo = null; using (IFCTransaction transaction = new IFCTransaction(file)) { // For IFC4RV export, Ceiling will be split into its parts(temporarily) in order to export the ceiling by its parts bool exportByComponents = ExporterUtil.ShouldExportByComponents(element, exportParts); // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd); IList <IFCAnyHandle> representations = new List <IFCAnyHandle>(); using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd)) { using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData()) { ElementId categoryId = CategoryUtil.GetSafeCategoryId(element); IFCAnyHandle prodRep = null; if (!exportParts) { ecData.SetLocalPlacement(setter.LocalPlacement); ecData.PossibleExtrusionAxes = IFCExtrusionAxes.TryZ; BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow); if (exportByComponents) { prodRep = RepresentationUtil.CreateProductDefinitionShapeWithoutBodyRep(exporterIFC, element, categoryId, geomElem, representations); } else { prodRep = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC, element, categoryId, geomElem, bodyExporterOptions, null, ecData, true); } if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodRep)) { ecData.ClearOpenings(); return; } } // We will use the category of the element to set a default value for the covering. string defaultCoveringEnumType = null; if (categoryId == new ElementId(BuiltInCategory.OST_Ceilings)) { defaultCoveringEnumType = "CEILING"; } else if (categoryId == new ElementId(BuiltInCategory.OST_Floors)) { defaultCoveringEnumType = "FLOORING"; } else if (categoryId == new ElementId(BuiltInCategory.OST_Roofs)) { defaultCoveringEnumType = "ROOFING"; } string instanceGUID = GUIDUtil.CreateGUID(element); string coveringType = IFCValidateEntry.GetValidIFCPredefinedTypeType(/*element,*/ ifcEnumType, defaultCoveringEnumType, "IfcCoveringType"); IFCAnyHandle covering = IFCInstanceExporter.CreateCovering(exporterIFC, element, instanceGUID, ExporterCacheManager.OwnerHistoryHandle, setter.LocalPlacement, prodRep, coveringType); if (exportParts && !ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { PartExporter.ExportHostPart(exporterIFC, element, covering, productWrapper, setter, setter.LocalPlacement, null); } else if (exportByComponents) { IFCAnyHandle hostShapeRepFromParts = PartExporter.ExportHostPartAsShapeAspects(exporterIFC, element, prodRep, productWrapper, setter, setter.LocalPlacement, ElementId.InvalidElementId, out layersetInfo, ecData); } ExporterUtil.AddIntoComplexPropertyCache(covering, layersetInfo); IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcCovering, IFCEntityType.IfcCoveringType, coveringType); IFCAnyHandle typeHnd = ExporterUtil.CreateGenericTypeFromElement(element, exportInfo, file, ExporterCacheManager.OwnerHistoryHandle, coveringType, productWrapper); ExporterCacheManager.TypeRelationsCache.Add(typeHnd, covering); bool containInSpace = false; IFCAnyHandle localPlacementToUse = setter.LocalPlacement; // Ceiling containment in Space is generally required and not specific to any view if (ExporterCacheManager.CeilingSpaceRelCache.ContainsKey(element.Id)) { IList <ElementId> roomlist = ExporterCacheManager.CeilingSpaceRelCache[element.Id]; // Process Ceiling to be contained in a Space only when it is exactly bounding one Space if (roomlist.Count == 1) { productWrapper.AddElement(element, covering, setter, ecData, false, exportInfo); // Modify the Ceiling placement to be relative to the Space that it bounds IFCAnyHandle roomPlacement = IFCAnyHandleUtil.GetObjectPlacement(ExporterCacheManager.SpaceInfoCache.FindSpaceHandle(roomlist[0])); Transform relTrf = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(roomPlacement, localPlacementToUse); Transform inverseTrf = relTrf.Inverse; IFCAnyHandle relLocalPlacement = ExporterUtil.CreateAxis2Placement3D(file, inverseTrf.Origin, inverseTrf.BasisZ, inverseTrf.BasisX); IFCAnyHandleUtil.SetAttribute(localPlacementToUse, "PlacementRelTo", roomPlacement); GeometryUtil.SetRelativePlacement(localPlacementToUse, relLocalPlacement); ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomlist[0], covering); containInSpace = true; } } // if not contained in Space, assign it to default containment in Level if (!containInSpace) { productWrapper.AddElement(element, covering, setter, ecData, true, exportInfo); } if (!exportParts) { Ceiling ceiling = element as Ceiling; if (ceiling != null) { HostObjectExporter.ExportHostObjectMaterials(exporterIFC, ceiling, covering, geomElem, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, null, null); } else { ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geomElem, exporterIFC, element); CategoryUtil.CreateMaterialAssociation(exporterIFC, covering, matId); } } OpeningUtil.CreateOpeningsIfNecessary(covering, element, ecData, null, exporterIFC, ecData.GetLocalPlacement(), setter, productWrapper); } } transaction.Commit(); } }
/// <summary> /// Exports a roof or floor as a container of multiple roof slabs. Returns the handle, if successful. /// </summary> /// <param name="exporterIFC">The exporter.</param> /// <param name="ifcEnumType">The roof type.</param> /// <param name="element">The roof or floor element.</param> /// <param name="geometry">The geometry of the element.</param> /// <param name="productWrapper">The product wrapper.</param> /// <returns>The roof handle.</returns> /// <remarks>For floors, if there is only one component, return null, as we do not want to create a container.</remarks> public static IFCAnyHandle ExportRoofOrFloorAsContainer(ExporterIFC exporterIFC, string ifcEnumType, Element element, GeometryElement geometry, ProductWrapper productWrapper) { IFCFile file = exporterIFC.GetFile(); // We support ExtrusionRoofs, FootPrintRoofs, and Floors only. bool elementIsRoof = (element is ExtrusionRoof) || (element is FootPrintRoof); bool elementIsFloor = (element is Floor); if (!elementIsRoof && !elementIsFloor) { return(null); } Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcRoof; if (elementIsFloor) { elementClassTypeEnum = Common.Enums.IFCEntityType.IfcSlab; } IFCExportInfoPair roofExportType = new IFCExportInfoPair(elementClassTypeEnum, ifcEnumType); // Check the intended IFC entity or type name is in the exclude list specified in the UI if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return(null); } using (IFCTransaction transaction = 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)) { IFCAnyHandle localPlacement = setter.LocalPlacement; IList <HostObjectSubcomponentInfo> hostObjectSubcomponents = null; try { hostObjectSubcomponents = ExporterIFCUtils.ComputeSubcomponents(element as HostObject); } catch { return(null); } if (hostObjectSubcomponents == null) { return(null); } int numSubcomponents = hostObjectSubcomponents.Count; if (numSubcomponents == 0 || (elementIsFloor && numSubcomponents == 1)) { return(null); } IFCAnyHandle hostObjectHandle = null; try { using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData()) { IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; extrusionCreationData.SetLocalPlacement(localPlacement); extrusionCreationData.ReuseLocalPlacement = true; using (TransformSetter trfSetter = TransformSetter.Create()) { IList <GeometryObject> geometryList = new List <GeometryObject>(); geometryList.Add(geometry); trfSetter.InitializeFromBoundingBox(exporterIFC, geometryList, extrusionCreationData); IFCAnyHandle prodRepHnd = null; string elementGUID = GUIDUtil.CreateGUID(element); //string hostObjectType = IFCValidateEntry.GetValidIFCPredefinedType(element, ifcEnumType); if (elementIsRoof) { hostObjectHandle = IFCInstanceExporter.CreateRoof(exporterIFC, element, elementGUID, ownerHistory, localPlacement, prodRepHnd, ifcEnumType); } else { hostObjectHandle = IFCInstanceExporter.CreateSlab(exporterIFC, element, elementGUID, ownerHistory, localPlacement, prodRepHnd, ifcEnumType); } if (IFCAnyHandleUtil.IsNullOrHasNoValue(hostObjectHandle)) { return(null); } IList <IFCAnyHandle> elementHandles = new List <IFCAnyHandle>(); elementHandles.Add(hostObjectHandle); // If element is floor, then the profile curve loop of hostObjectSubComponent is computed from the top face of the floor // else if element is roof, then the profile curve loop is taken from the bottom face of the roof instead XYZ extrusionDir = elementIsFloor ? new XYZ(0, 0, -1) : new XYZ(0, 0, 1); ElementId catId = CategoryUtil.GetSafeCategoryId(element); IList <IFCAnyHandle> slabHandles = new List <IFCAnyHandle>(); IList <CurveLoop> hostObjectOpeningLoops = new List <CurveLoop>(); double maximumScaledDepth = 0.0; using (IFCExtrusionCreationData slabExtrusionCreationData = new IFCExtrusionCreationData()) { slabExtrusionCreationData.SetLocalPlacement(extrusionCreationData.GetLocalPlacement()); slabExtrusionCreationData.ReuseLocalPlacement = false; slabExtrusionCreationData.ForceOffset = true; int loopNum = 0; int subElementStart = elementIsRoof ? (int)IFCRoofSubElements.RoofSlabStart : (int)IFCSlabSubElements.SubSlabStart; string subSlabType = elementIsRoof ? "ROOF" : ifcEnumType; foreach (HostObjectSubcomponentInfo hostObjectSubcomponent in hostObjectSubcomponents) { trfSetter.InitializeFromBoundingBox(exporterIFC, geometryList, slabExtrusionCreationData); Plane plane = hostObjectSubcomponent.GetPlane(); Transform lcs = GeometryUtil.CreateTransformFromPlane(plane); IList <CurveLoop> curveLoops = new List <CurveLoop>(); CurveLoop slabCurveLoop = hostObjectSubcomponent.GetCurveLoop(); curveLoops.Add(slabCurveLoop); double slope = Math.Abs(plane.Normal.Z); double scaledDepth = UnitUtil.ScaleLength(hostObjectSubcomponent.Depth); double scaledExtrusionDepth = scaledDepth * slope; IFCAnyHandle shapeRep = ExtrusionExporter.CreateExtrudedSolidFromCurveLoop(exporterIFC, null, curveLoops, lcs, extrusionDir, scaledExtrusionDepth, false); if (IFCAnyHandleUtil.IsNullOrHasNoValue(shapeRep)) { productWrapper.ClearInternalHandleWrapperData(element); return(null); } ElementId matId = HostObjectExporter.GetFirstLayerMaterialId(element as HostObject); BodyExporter.CreateSurfaceStyleForRepItem(exporterIFC, element.Document, shapeRep, matId); HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>(); bodyItems.Add(shapeRep); shapeRep = RepresentationUtil.CreateSweptSolidRep(exporterIFC, element, catId, exporterIFC.Get3DContextHandle("Body"), bodyItems, null); IList <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>(); shapeReps.Add(shapeRep); IFCAnyHandle repHnd = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps); // Allow support for up to 256 named IfcSlab components, as defined in IFCSubElementEnums.cs. string slabGUID = (loopNum < 256) ? GUIDUtil.CreateSubElementGUID(element, subElementStart + loopNum) : GUIDUtil.CreateGUID(); IFCAnyHandle slabPlacement = ExporterUtil.CreateLocalPlacement(file, slabExtrusionCreationData.GetLocalPlacement(), null); IFCAnyHandle slabHnd = IFCInstanceExporter.CreateSlab(exporterIFC, element, slabGUID, ownerHistory, slabPlacement, repHnd, subSlabType); IFCExportInfoPair exportType = new IFCExportInfoPair(IFCEntityType.IfcSlab, subSlabType); //slab quantities slabExtrusionCreationData.ScaledLength = scaledExtrusionDepth; slabExtrusionCreationData.ScaledArea = UnitUtil.ScaleArea(UnitUtil.ScaleArea(hostObjectSubcomponent.AreaOfCurveLoop)); slabExtrusionCreationData.ScaledOuterPerimeter = UnitUtil.ScaleLength(curveLoops[0].GetExactLength()); slabExtrusionCreationData.Slope = UnitUtil.ScaleAngle(MathUtil.SafeAcos(Math.Abs(slope))); ExporterUtil.RelateObject(exporterIFC, hostObjectHandle, slabHnd); IFCExportInfoPair slabRoofExportType = new IFCExportInfoPair(IFCEntityType.IfcSlab, slabRoofPredefinedType); productWrapper.AddElement(null, slabHnd, setter, slabExtrusionCreationData, false, slabRoofExportType); CategoryUtil.CreateMaterialAssociation(exporterIFC, slabHnd, matId); // Create type IFCAnyHandle slabRoofTypeHnd = ExporterUtil.CreateGenericTypeFromElement(element, slabRoofExportType, exporterIFC.GetFile(), ownerHistory, slabRoofPredefinedType, productWrapper); ExporterCacheManager.TypeRelationsCache.Add(slabRoofTypeHnd, slabHnd); elementHandles.Add(slabHnd); slabHandles.Add(slabHnd); hostObjectOpeningLoops.Add(slabCurveLoop); maximumScaledDepth = Math.Max(maximumScaledDepth, scaledDepth); loopNum++; } } productWrapper.AddElement(element, hostObjectHandle, setter, extrusionCreationData, true, roofExportType); ExporterUtil.RelateObjects(exporterIFC, null, hostObjectHandle, slabHandles); OpeningUtil.AddOpeningsToElement(exporterIFC, elementHandles, hostObjectOpeningLoops, element, null, maximumScaledDepth, null, setter, localPlacement, productWrapper); transaction.Commit(); return(hostObjectHandle); } } } catch { // SOmething wrong with the above process, unable to create the extrusion data. Reset any internal handles that may have been partially created since they are not committed productWrapper.ClearInternalHandleWrapperData(element); return(null); } finally { exporterIFC.ClearFaceWithElementHandleMap(); } } } }
public void Execute() { this._result = ParameterUtil.GetFilterWithTag(this.Query.Execute(), this.TagName); }
/// <summary> /// Exports a beam to IFC beam if it has an axis representation and only one Solid as its geometry, ideally as an extrusion, potentially with clippings and openings. /// </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> /// <param name="dontExport">An output value that says that the element shouldn't be exported at all.</param> /// <returns>The created handle.</returns> /// <remarks>In the original implementation, the ExportBeam function would export each beam as its own individual geometry (that is, not use representation maps). /// For non-standard beams, this could result in massive IFC files. Now, we use the ExportBeamAsStandardElement function and limit its scope, and instead /// resort to the standard FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem for more complicated objects categorized as beams. This has the following pros and cons: /// Pro: possiblity for massively reduced file sizes for files containing repeated complex beam families /// Con: some beams that may have had an "Axis" representation before will no longer have them, although this possibility is minimized. /// Con: some beams that have 1 Solid and an axis, but that Solid will be heavily faceted, won't be helped by this improvement. /// It is intended that we phase out this routine entirely and instead teach ExportFamilyInstanceAsMappedItem how to sometimes export the Axis representation for beams.</remarks> public static IFCAnyHandle ExportBeamAsStandardElement(ExporterIFC exporterIFC, Element element, IFCExportInfoPair exportType, GeometryElement geometryElement, ProductWrapper productWrapper, out bool dontExport) { dontExport = true; IList <GeometryObject> geomObjects = BeamGeometryToExport(exporterIFC, element, geometryElement, out dontExport); if (dontExport) { return(null); } IFCAnyHandle beam = null; IFCFile file = exporterIFC.GetFile(); MaterialAndProfile materialAndProfile = null; IFCAnyHandle materialProfileSet = null; using (IFCTransaction transaction = new IFCTransaction(file)) { BeamAxisInfo axisInfo = GetBeamAxisTransform(element); bool canExportAxis = (axisInfo != null); Curve curve = canExportAxis ? axisInfo.Axis : null; XYZ beamDirection = canExportAxis ? axisInfo.AxisDirection : null; Transform orientTrf = canExportAxis ? axisInfo.LCSAsTransform : null; // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd); using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, orientTrf, overrideContainerId, overrideContainerHnd)) { IFCAnyHandle localPlacement = setter.LocalPlacement; 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; } ElementId catId = CategoryUtil.GetSafeCategoryId(element); // 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; // The list of materials in the solids or meshes. ICollection <ElementId> materialIds = null; // If the beam is a FamilyInstance, and it uses transformed FamilySymbol geometry only, then // let's only try to CreateBeamGeometryAsExtrusion unsuccesfully once. Otherwise, we can spend a lot of time trying // unsuccessfully to do so. bool tryToCreateBeamGeometryAsExtrusion = true; //bool useFamilySymbolGeometry = (element is FamilyInstance) ? !ExporterIFCUtils.UsesInstanceGeometry(element as FamilyInstance) : false; bool useFamilySymbolGeometry = (element is FamilyInstance) ? !GeometryUtil.UsesInstanceGeometry(element as FamilyInstance) : false; ElementId beamTypeId = element.GetTypeId(); if (useFamilySymbolGeometry) { tryToCreateBeamGeometryAsExtrusion = !ExporterCacheManager.CanExportBeamGeometryAsExtrusionCache.ContainsKey(beamTypeId) || ExporterCacheManager.CanExportBeamGeometryAsExtrusionCache[beamTypeId]; } // The representation handle generated from one of the methods below. BeamBodyAsExtrusionInfo extrusionInfo = null; if (tryToCreateBeamGeometryAsExtrusion) { extrusionInfo = CreateBeamGeometryAsExtrusion(exporterIFC, element, catId, geomObjects, axisInfo); if (useFamilySymbolGeometry) { ExporterCacheManager.CanExportBeamGeometryAsExtrusionCache[beamTypeId] = (extrusionInfo != null); } } if (extrusionInfo != null && extrusionInfo.DontExport) { dontExport = true; return(null); } IFCAnyHandle repHnd = (extrusionInfo != null) ? extrusionInfo.RepresentationHandle : null; if (!IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd)) { materialIds = extrusionInfo.Materials; extrusionCreationData.Slope = extrusionInfo.Slope; } else { // Here is where we limit the scope of how complex a case we will still try to export as a standard element. // This is explicitly added so that many curved beams that can be represented by a reasonable facetation because of the // SweptSolidExporter can still have an Axis representation. BodyData bodyData = null; BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow); if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { bodyExporterOptions.CollectMaterialAndProfile = false; } else { bodyExporterOptions.CollectMaterialAndProfile = true; } if (geomObjects != null && geomObjects.Count == 1 && geomObjects[0] is Solid) { bodyData = BodyExporter.ExportBody(exporterIFC, element, catId, ElementId.InvalidElementId, geomObjects[0], bodyExporterOptions, extrusionCreationData); repHnd = bodyData.RepresentationHnd; materialIds = bodyData.MaterialIds; if (!bodyData.OffsetTransform.IsIdentity) { offsetTransform = bodyData.OffsetTransform; } materialAndProfile = bodyData.MaterialAndProfile; } } if (IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd)) { extrusionCreationData.ClearOpenings(); return(null); } IList <IFCAnyHandle> representations = new List <IFCAnyHandle>(); IFCAnyHandle axisRep = CreateBeamAxis(exporterIFC, element, catId, axisInfo, offsetTransform); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(axisRep)) { 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); beam = IFCInstanceExporter.CreateBeam(exporterIFC, element, instanceGUID, ExporterCacheManager.OwnerHistoryHandle, extrusionCreationData.GetLocalPlacement(), prodRep, exportType.ValidatedPredefinedType); IFCAnyHandle mpSetUsage; if (materialProfileSet != null) { mpSetUsage = IFCInstanceExporter.CreateMaterialProfileSetUsage(file, materialProfileSet, null, null); } productWrapper.AddElement(element, beam, setter, extrusionCreationData, true, exportType); ExportBeamType(exporterIFC, productWrapper, beam, element, exportType.ValidatedPredefinedType); 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, null); if (materialIds.Count != 0) { CategoryUtil.CreateMaterialAssociation(exporterIFC, beam, materialIds); } // Register the beam's IFC handle for later use by truss and beam system export. ExporterCacheManager.ElementToHandleCache.Register(element.Id, beam, exportType); } } transaction.Commit(); return(beam); } }
/// <summary> /// Exports curtain object as container. /// </summary> /// <param name="allSubElements"> /// Collection of elements contained in the host curtain element. /// </param> /// <param name="wallElement"> /// The curtain wall element. /// </param> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="productWrapper"> /// The ProductWrapper. /// </param> public static void ExportCurtainObjectCommonAsContainer(ICollection <ElementId> allSubElements, Element wallElement, ExporterIFC exporterIFC, ProductWrapper origWrapper, PlacementSetter currSetter) { if (wallElement == null) { return; } string overrideCADLayer = null; if (ParameterUtil.GetStringValueFromElementOrSymbol(wallElement, "IFCCadLayer", out overrideCADLayer) == null || string.IsNullOrWhiteSpace(overrideCADLayer)) { if ((ParameterUtil.GetStringValueFromElementOrSymbol(wallElement, "IfcPresentationLayer", out overrideCADLayer) == null) || string.IsNullOrWhiteSpace(overrideCADLayer)) { overrideCADLayer = ExporterStateManager.GetCurrentCADLayerOverride(); } } using (ExporterStateManager.CADLayerOverrideSetter layerSetter = new ExporterStateManager.CADLayerOverrideSetter(overrideCADLayer)) { HashSet <ElementId> alreadyVisited = new HashSet <ElementId>(); // just in case. Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); { foreach (ElementId subElemId in allSubElements) { using (ProductWrapper productWrapper = ProductWrapper.Create(origWrapper)) { Element subElem = wallElement.Document.GetElement(subElemId); if (subElem == null) { continue; } if (alreadyVisited.Contains(subElem.Id)) { continue; } alreadyVisited.Add(subElem.Id); // Respect element visibility settings. if (!ElementFilteringUtil.CanExportElement(exporterIFC, subElem, false) || !ElementFilteringUtil.IsElementVisible(subElem)) { continue; } GeometryElement geomElem = subElem.get_Geometry(geomOptions); if (geomElem == null) { continue; } try { if (subElem is FamilyInstance) { string ifcEnumType; IFCExportInfoPair exportType = ExporterUtil.GetExportType(exporterIFC, subElem, out ifcEnumType); if (subElem is Mullion) { if (ExporterCacheManager.ExportOptionsCache.ExportAs2x2) { ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper, exportType); } else { IFCAnyHandle currLocalPlacement = currSetter.LocalPlacement; if (exportType.ExportInstance == IFCEntityType.IfcCurtainWall) { // By default, panels and mullions are set to the same category as their parent. In this case, // ask to get the exportType from the category id, since we don't want to inherit the parent class. ifcEnumType = "MULLION"; exportType.SetValueWithPair(IFCEntityType.IfcMemberType, ifcEnumType); } FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem(exporterIFC, subElem as Mullion, exportType, exportType.ValidatedPredefinedType, productWrapper, ElementId.InvalidElementId, null, currLocalPlacement); } } else { FamilyInstance subFamInst = subElem as FamilyInstance; if (exportType.ExportInstance == IFCEntityType.IfcCurtainWall) { // By default, panels and mullions are set to the same category as their parent. In this case, // ask to get the exportType from the category id, since we don't want to inherit the parent class. ElementId catId = CategoryUtil.GetSafeCategoryId(subElem); exportType = ElementFilteringUtil.GetExportTypeFromCategoryId(catId, out ifcEnumType); } if (ExporterCacheManager.ExportOptionsCache.ExportAs2x2) { if ((exportType.ExportInstance == IFCEntityType.UnKnown) || (exportType.ExportInstance == IFCEntityType.IfcPlate) || (exportType.ExportInstance == IFCEntityType.IfcMember)) { exportType.SetValueWithPair(IFCEntityType.IfcBuildingElementProxy, ifcEnumType); } } else { if (exportType.ExportInstance == IFCEntityType.UnKnown) { ifcEnumType = "CURTAIN_PANEL"; exportType.SetValueWithPair(IFCEntityType.IfcPlateType, ifcEnumType); } } IFCAnyHandle currLocalPlacement = currSetter.LocalPlacement; using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData()) { FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem(exporterIFC, subFamInst, exportType, ifcEnumType, productWrapper, ElementId.InvalidElementId, null, currLocalPlacement); } } } else if (subElem is CurtainGridLine) { ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper); } else if (subElem is Wall) { WallExporter.ExportWall(exporterIFC, null, subElem, null, geomElem, productWrapper); } } catch (Exception ex) { if (ExporterUtil.IsFatalException(wallElement.Document, ex)) { throw ex; } continue; } } } } } }
/// <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; IFCAnyHandle localPlacement = null; PlacementSetter placementSetter = null; IFCLevelInfo levelInfo = null; bool relateToLevel = true; string ifcEnumType; IFCExportInfoPair exportAs = ExporterUtil.GetObjectExportType(exporterIFC, element, out ifcEnumType); if (exportAs.ExportInstance == IFCEntityType.IfcSystem) { string name = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element)); string description = NamingUtil.GetDescriptionOverride(element, null); string objectType = NamingUtil.GetObjectTypeOverride(element, NamingUtil.GetFamilyAndTypeName(element)); 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>() { ExporterCacheManager.BuildingHandle }; string relServicesBuildingsGuid = GUIDUtil.GenerateIFCGuidFrom(IFCEntityType.IfcRelServicesBuildings, assemblyInstanceHnd); IFCAnyHandle relServicesBuildings = IFCInstanceExporter.CreateRelServicesBuildings(file, relServicesBuildingsGuid, ExporterCacheManager.OwnerHistoryHandle, null, null, assemblyInstanceHnd, relatedBuildings); relateToLevel = false; // Already related to the building via IfcRelServicesBuildings. } else { // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd); using (placementSetter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd)) { IFCAnyHandle representation = null; // We have limited support for exporting assemblies as other container types. localPlacement = placementSetter.LocalPlacement; levelInfo = placementSetter.LevelInfo; switch (exportAs.ExportInstance) { case IFCEntityType.IfcCurtainWall: assemblyInstanceHnd = IFCInstanceExporter.CreateCurtainWall(exporterIFC, element, guid, ownerHistory, localPlacement, representation, ifcEnumType); break; case IFCEntityType.IfcRamp: string rampPredefinedType = RampExporter.GetIFCRampType(ifcEnumType); assemblyInstanceHnd = IFCInstanceExporter.CreateRamp(exporterIFC, element, guid, ownerHistory, localPlacement, representation, rampPredefinedType); break; case IFCEntityType.IfcRoof: assemblyInstanceHnd = IFCInstanceExporter.CreateRoof(exporterIFC, element, guid, ownerHistory, localPlacement, representation, ifcEnumType); break; case IFCEntityType.IfcStair: string stairPredefinedType = StairsExporter.GetIFCStairType(ifcEnumType); assemblyInstanceHnd = IFCInstanceExporter.CreateStair(exporterIFC, element, guid, ownerHistory, localPlacement, representation, stairPredefinedType); break; case IFCEntityType.IfcWall: assemblyInstanceHnd = IFCInstanceExporter.CreateWall(exporterIFC, element, guid, ownerHistory, localPlacement, representation, ifcEnumType); break; default: string objectType = NamingUtil.GetObjectTypeOverride(element, NamingUtil.GetFamilyAndTypeName(element)); IFCElementAssemblyType assemblyPredefinedType = GetPredefinedTypeFromObjectType(objectType); assemblyInstanceHnd = IFCInstanceExporter.CreateElementAssembly(exporterIFC, element, guid, ownerHistory, localPlacement, representation, 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, exportAs); ExporterCacheManager.AssemblyInstanceCache.RegisterAssemblyInstance(element.Id, assemblyInstanceHnd); tr.Commit(); return(true); } }
/// <summary> /// Export the individual part (IfcBuildingElementPart). /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="partElement">The part element to export.</param> /// <param name="geometryElement">The geometry of part.</param> /// <param name="productWrapper">The ProductWrapper object.</param> /// <param name="placementSetter"></param> /// <param name="originalPlacement"></param> /// <param name="range"></param> /// <param name="ifcExtrusionAxes"></param> /// <param name="hostElement">The host of the part. This can be null.</param> /// <param name="overrideLevelId">The id of the level that the part is one, overridding other sources.</param> /// <param name="asBuildingElement">If true, export the Part as a building element instead of an IfcElementPart.</param> public static void ExportPart(ExporterIFC exporterIFC, Element partElement, ProductWrapper productWrapper, PlacementSetter placementSetter, IFCAnyHandle originalPlacement, IFCRange range, IFCExtrusionAxes ifcExtrusionAxes, Element hostElement, ElementId overrideLevelId, bool asBuildingElement) { if (!ElementFilteringUtil.IsElementVisible(partElement)) { return; } Part part = partElement as Part; if (part == null) { return; } // We don't know how to export a part as a building element if we don't know it's host. if (asBuildingElement && (hostElement == null)) { return; } if (!asBuildingElement) { // Check the intended IFC entity or type name is in the exclude list specified in the UI Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcBuildingElementPart; if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return; } } else { string ifcEnumType = null; IFCExportInfoPair exportType = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType); // 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; } } } PlacementSetter standalonePlacementSetter = null; bool standaloneExport = hostElement == null || asBuildingElement; ElementId partExportLevelId = (overrideLevelId != null) ? overrideLevelId : null; if (partExportLevelId == null && standaloneExport) { partExportLevelId = partElement.LevelId; } if (partExportLevelId == null) { if (hostElement == null || (part.OriginalCategoryId != hostElement.Category.Id)) { return; } partExportLevelId = hostElement.LevelId; } if (ExporterCacheManager.PartExportedCache.HasExported(partElement.Id, partExportLevelId)) { return; } Options options = GeometryUtil.GetIFCExportGeometryOptions(); View ownerView = partElement.Document.GetElement(partElement.OwnerViewId) as View; if (ownerView != null) { options.View = ownerView; } GeometryElement geometryElement = partElement.get_Geometry(options); if (geometryElement == null) { return; } try { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(file)) { IFCAnyHandle partPlacement = null; if (standaloneExport) { Transform orientationTrf = Transform.Identity; IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, partElement, out overrideContainerHnd); if (overrideContainerId != ElementId.InvalidElementId && (partExportLevelId == null || partExportLevelId == ElementId.InvalidElementId)) { partExportLevelId = overrideContainerId; } standalonePlacementSetter = PlacementSetter.Create(exporterIFC, partElement, null, orientationTrf, partExportLevelId, overrideContainerHnd); partPlacement = standalonePlacementSetter.LocalPlacement; } else { //partPlacement = ExporterUtil.CreateLocalPlacement(file, null, null); partPlacement = ExporterUtil.CreateLocalPlacement(file, originalPlacement, null); } bool validRange = (range != null && !MathUtil.IsAlmostZero(range.Start - range.End)); SolidMeshGeometryInfo solidMeshInfo; if (validRange) { solidMeshInfo = GeometryUtil.GetSplitClippedSolidMeshGeometry(geometryElement, range); if (solidMeshInfo.GetSolids().Count == 0 && solidMeshInfo.GetMeshes().Count == 0) { return; } } else { solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement); } using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData()) { extrusionCreationData.SetLocalPlacement(partPlacement); extrusionCreationData.ReuseLocalPlacement = false; extrusionCreationData.PossibleExtrusionAxes = ifcExtrusionAxes; IList <Solid> solids = new List <Solid>();; IList <Mesh> meshes = new List <Mesh>(); IList <GeometryObject> gObjs = FamilyExporterUtil.RemoveInvisibleSolidsAndMeshes(partElement.Document, exporterIFC, solidMeshInfo.GetSolids(), solidMeshInfo.GetMeshes()); foreach (GeometryObject gObj in gObjs) { if (gObj is Solid) { solids.Add(gObj as Solid); } else if (gObj is Mesh) { meshes.Add(gObj as Mesh); } } ElementId catId = CategoryUtil.GetSafeCategoryId(partElement); ElementId hostCatId = CategoryUtil.GetSafeCategoryId(hostElement); BodyData bodyData = null; BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow); if (solids.Count > 0 || meshes.Count > 0) { bodyData = BodyExporter.ExportBody(exporterIFC, partElement, catId, ElementId.InvalidElementId, solids, meshes, bodyExporterOptions, extrusionCreationData); } else { IList <GeometryObject> geomlist = new List <GeometryObject>(); geomlist.Add(geometryElement); bodyData = BodyExporter.ExportBody(exporterIFC, partElement, catId, ElementId.InvalidElementId, geomlist, bodyExporterOptions, extrusionCreationData); } IFCAnyHandle bodyRep = bodyData.RepresentationHnd; if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep)) { extrusionCreationData.ClearOpenings(); return; } IList <IFCAnyHandle> representations = new List <IFCAnyHandle>(); representations.Add(bodyRep); IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geometryElement, Transform.Identity); if (boundingBoxRep != null) { representations.Add(boundingBoxRep); } IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; string partGUID = GUIDUtil.CreateGUID(partElement); string ifcEnumType = null; IFCExportInfoPair exportType = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType); IFCAnyHandle ifcPart = null; if (!asBuildingElement) { ifcPart = IFCInstanceExporter.CreateBuildingElementPart(exporterIFC, partElement, partGUID, ownerHistory, extrusionCreationData.GetLocalPlacement(), prodRep); } else { switch (exportType.ExportInstance) { case IFCEntityType.IfcColumn: ifcPart = IFCInstanceExporter.CreateColumn(exporterIFC, partElement, partGUID, ownerHistory, extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType); break; case IFCEntityType.IfcCovering: ifcPart = IFCInstanceExporter.CreateCovering(exporterIFC, partElement, partGUID, ownerHistory, extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType); break; case IFCEntityType.IfcFooting: ifcPart = IFCInstanceExporter.CreateFooting(exporterIFC, partElement, partGUID, ownerHistory, extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType); break; case IFCEntityType.IfcPile: ifcPart = IFCInstanceExporter.CreatePile(exporterIFC, partElement, partGUID, ownerHistory, extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType, null); break; case IFCEntityType.IfcRoof: ifcPart = IFCInstanceExporter.CreateRoof(exporterIFC, partElement, partGUID, ownerHistory, extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType); break; case IFCEntityType.IfcSlab: { // TODO: fix this elsewhere. if (ExporterUtil.IsNotDefined(ifcEnumType)) { if (hostCatId == new ElementId(BuiltInCategory.OST_Floors)) { ifcEnumType = "FLOOR"; } else if (hostCatId == new ElementId(BuiltInCategory.OST_Roofs)) { ifcEnumType = "ROOF"; } } ifcPart = IFCInstanceExporter.CreateSlab(exporterIFC, partElement, partGUID, ownerHistory, extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType); } break; case IFCEntityType.IfcWall: ifcPart = IFCInstanceExporter.CreateWall(exporterIFC, partElement, partGUID, ownerHistory, extrusionCreationData.GetLocalPlacement(), prodRep, ifcEnumType); break; default: ifcPart = IFCInstanceExporter.CreateBuildingElementProxy(exporterIFC, partElement, partGUID, ownerHistory, extrusionCreationData.GetLocalPlacement(), prodRep, exportType.ValidatedPredefinedType); break; } } bool containedInLevel = standaloneExport; PlacementSetter whichPlacementSetter = containedInLevel ? standalonePlacementSetter : placementSetter; productWrapper.AddElement(partElement, ifcPart, whichPlacementSetter, extrusionCreationData, containedInLevel, exportType); OpeningUtil.CreateOpeningsIfNecessary(ifcPart, partElement, extrusionCreationData, bodyData.OffsetTransform, exporterIFC, extrusionCreationData.GetLocalPlacement(), whichPlacementSetter, productWrapper); //Add the exported part to exported cache. TraceExportedParts(partElement, partExportLevelId, standaloneExport ? ElementId.InvalidElementId : hostElement.Id); CategoryUtil.CreateMaterialAssociation(exporterIFC, ifcPart, bodyData.MaterialIds); transaction.Commit(); } } } finally { if (standalonePlacementSetter != null) { standalonePlacementSetter.Dispose(); } } }
/// <summary> /// Creates IfcPresentationStyleAssignment for text element type. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="textElemType"> /// The text note element type. /// </param> /// <param name="cache"> /// The cache of IfcPresentationStyleAssignment. /// </param> static void CreatePresentationStyleAssignmentForTextElementType(ExporterIFC exporterIFC, TextElementType textElemType, PresentationStyleAssignmentCache cache) { IFCFile file = exporterIFC.GetFile(); string fontName; if (ParameterUtil.GetStringValueFromElement(textElemType, BuiltInParameter.TEXT_FONT, out fontName) == null) { fontName = null; } double fontSize; if (ParameterUtil.GetDoubleValueFromElement(textElemType, BuiltInParameter.TEXT_SIZE, out fontSize) == null) { fontSize = -1.0; } double viewScale = 100.0; // currently hardwired. fontSize = UnitUtil.ScaleLength(fontSize * viewScale); string ifcPreDefinedItemName = "Text Font"; IList <string> fontNameList = new List <string>(); fontNameList.Add(fontName); IFCAnyHandle textSyleFontModelHnd = IFCInstanceExporter.CreateTextStyleFontModel(file, ifcPreDefinedItemName, fontNameList, null, null, null, IFCDataUtil.CreateAsPositiveLengthMeasure(fontSize)); int color; ParameterUtil.GetIntValueFromElement(textElemType, BuiltInParameter.LINE_COLOR, out color); double blueVal = ((double)((color & 0xff0000) >> 16)) / 255.0; double greenVal = ((double)((color & 0xff00) >> 8)) / 255.0; double redVal = ((double)(color & 0xff)) / 255.0; IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(file, null, redVal, greenVal, blueVal); IFCAnyHandle fontColorHnd = IFCInstanceExporter.CreateTextStyleForDefinedFont(file, colorHnd, null); string ifcAttrName = textElemType.Name; IFCAnyHandle textStyleHnd = IFCInstanceExporter.CreateTextStyle(file, textElemType.Name, fontColorHnd, null, textSyleFontModelHnd); if (IFCAnyHandleUtil.IsNullOrHasNoValue(textStyleHnd)) { return; } HashSet <IFCAnyHandle> presStyleSet = new HashSet <IFCAnyHandle>(); presStyleSet.Add(textStyleHnd); IFCAnyHandle presStyleHnd = IFCInstanceExporter.CreatePresentationStyleAssignment(file, presStyleSet); if (IFCAnyHandleUtil.IsNullOrHasNoValue(presStyleHnd)) { return; } cache.Register(textElemType.Id, presStyleHnd); }
/// <summary> /// Exports a generic element as an IfcSlab.</summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="floor">The floor element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="ifcEnumType">The string value represents the IFC type.</param> /// <param name="productWrapper">The ProductWrapper.</param> /// <returns>True if the floor is exported successfully, false otherwise.</returns> public static void ExportGenericSlab(ExporterIFC exporterIFC, Element slabElement, GeometryElement geometryElement, string ifcEnumType, ProductWrapper productWrapper) { if (geometryElement == null) { return; } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { using (IFCTransformSetter transformSetter = IFCTransformSetter.Create()) { // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, slabElement, out overrideContainerHnd); using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, slabElement, null, null, overrideContainerId, overrideContainerHnd)) { using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData()) { bool exportParts = PartExporter.CanExportParts(slabElement); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; IFCAnyHandle localPlacement = placementSetter.LocalPlacement; IFCAnyHandle prodDefHnd = null; bool isBRepSlabHnd = false; if (!exportParts) { ecData.SetLocalPlacement(localPlacement); ElementId catId = CategoryUtil.GetSafeCategoryId(slabElement); BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.Medium); BodyData bodyData; prodDefHnd = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC, slabElement, catId, geometryElement, bodyExporterOptions, null, ecData, out bodyData); if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodDefHnd)) { ecData.ClearOpenings(); return; } isBRepSlabHnd = (bodyData.ShapeRepresentationType == ShapeRepresentationType.Brep || bodyData.ShapeRepresentationType == ShapeRepresentationType.Tessellation); } // Create the slab from either the extrusion or the BRep information. string ifcGUID = GUIDUtil.CreateGUID(slabElement); string entityType = IFCValidateEntry.GetValidIFCType <IFCSlabType>(slabElement, ifcEnumType, "FLOOR"); IFCAnyHandle slabHnd = IFCInstanceExporter.CreateSlab(exporterIFC, slabElement, ifcGUID, ownerHistory, localPlacement, exportParts ? null : prodDefHnd, entityType); IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcSlab, entityType); if (IFCAnyHandleUtil.IsNullOrHasNoValue(slabHnd)) { return; } if (exportParts) { PartExporter.ExportHostPart(exporterIFC, slabElement, slabHnd, productWrapper, placementSetter, localPlacement, null); } productWrapper.AddElement(slabElement, slabHnd, placementSetter, ecData, true, exportInfo); if (!exportParts) { IFCAnyHandle typeHnd = ExporterUtil.CreateGenericTypeFromElement(slabElement, exportInfo, file, ownerHistory, entityType, productWrapper); ExporterCacheManager.TypeRelationsCache.Add(typeHnd, slabHnd); if (slabElement is HostObject) { HostObject hostObject = slabElement as HostObject; HostObjectExporter.ExportHostObjectMaterials(exporterIFC, hostObject, slabHnd, geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, isBRepSlabHnd, typeHnd); } else if (slabElement is FamilyInstance) { ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, slabElement); //Document doc = slabElement.Document; if (typeHnd != null) { CategoryUtil.CreateMaterialAssociation(exporterIFC, typeHnd, matId); } else { CategoryUtil.CreateMaterialAssociation(exporterIFC, slabHnd, matId); } } OpeningUtil.CreateOpeningsIfNecessary(slabHnd, slabElement, ecData, null, exporterIFC, ecData.GetLocalPlacement(), placementSetter, productWrapper); } } } tr.Commit(); return; } } }
/// <summary> /// Exports a curve element to IFC curve annotation. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="curveElement"> /// The curve element to be exported. /// </param> /// <param name="geometryElement"> /// The geometry element. /// </param> /// <param name="productWrapper"> /// The ProductWrapper. /// </param> public static void ExportCurveElement(ExporterIFC exporterIFC, CurveElement curveElement, GeometryElement geometryElement, ProductWrapper productWrapper) { if (geometryElement == null || !ShouldCurveElementBeExported(curveElement)) { return; } SketchPlane sketchPlane = curveElement.SketchPlane; if (sketchPlane == 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.IfcAnnotation; if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return; } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(file)) { // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, curveElement, out overrideContainerHnd); using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, curveElement, null, null, overrideContainerId, overrideContainerHnd)) { IFCAnyHandle localPlacement = setter.LocalPlacement; IFCAnyHandle axisPlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement); Plane planeSK = sketchPlane.GetPlane(); XYZ projDir = planeSK.Normal; XYZ origin = planeSK.Origin; bool useOffsetTrf = false; if (projDir.IsAlmostEqualTo(XYZ.BasisZ)) { XYZ offset = XYZ.BasisZ * setter.Offset; origin -= offset; } else { useOffsetTrf = true; } Transform curveLCS = GeometryUtil.CreateTransformFromPlane(planeSK); curveLCS.Origin = origin; IList <IFCAnyHandle> curves = null; if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { Transform trf = null; if (useOffsetTrf) { XYZ offsetOrig = -XYZ.BasisZ * setter.Offset; trf = Transform.CreateTranslation(offsetOrig); } curves = new List <IFCAnyHandle>(); //Curve curve = (geometryElement as GeometryObject) as Curve; List <Curve> curvesFromGeomElem = GeometryUtil.GetCurvesFromGeometryElement(geometryElement); foreach (Curve curve in curvesFromGeomElem) { IFCAnyHandle curveHnd; try { curveHnd = GeometryUtil.CreatePolyCurveFromCurve(exporterIFC, curve, trf); } catch { curveHnd = GeometryUtil.OutdatedCreatePolyCurveFromCurve(exporterIFC, curve, trf); } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveHnd)) { curves.Add(curveHnd); } } } else { IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, curveLCS, projDir, false); if (useOffsetTrf) { XYZ offsetOrig = -XYZ.BasisZ * setter.Offset; Transform trf = Transform.CreateTranslation(offsetOrig); ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false, trf); } else { ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false); } curves = info.GetCurves(); } if (curves.Count != 1) { throw new Exception("IFC: expected 1 curve when export curve element."); } HashSet <IFCAnyHandle> curveSet = new HashSet <IFCAnyHandle>(curves); IFCAnyHandle repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(file, curveSet); IFCAnyHandle curveStyle = file.CreateStyle(exporterIFC, repItemHnd); CurveAnnotationCache annotationCache = ExporterCacheManager.CurveAnnotationCache; IFCAnyHandle curveAnno = annotationCache.GetAnnotation(sketchPlane.Id, curveStyle); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveAnno)) { AddCurvesToAnnotation(curveAnno, curves); } else { curveAnno = CreateCurveAnnotation(exporterIFC, curveElement, curveElement.Category.Id, sketchPlane.Id, curveLCS, curveStyle, setter, localPlacement, repItemHnd); productWrapper.AddAnnotation(curveAnno, setter.LevelInfo, true); annotationCache.AddAnnotation(sketchPlane.Id, curveStyle, curveAnno); } } transaction.Commit(); } }
/// <summary> /// Create IfcClassification references from hardwired or custom classification code fields. /// </summary> /// <param name="exporterIFC">The exporterIFC class.</param> /// <param name="file">The IFC file class.</param> /// <param name="element">The element to export.</param> /// <param name="elemHnd">The corresponding IFC entity handle.</param> /// <returns>True if a classification or classification reference is created.</returns> public static bool CreateClassification(ExporterIFC exporterIFC, IFCFile file, Element element, IFCAnyHandle elemHnd) { bool createdClassification = false; string paramClassificationCode = ""; string baseClassificationCodeFieldName = "ClassificationCode"; IList <string> customClassificationCodeNames = new List <string>(); string classificationName = null; string classificationCode = null; string classificationDescription = null; int customPass = 0; int standardPass = 1; int numCustomCodes = ExporterCacheManager.ClassificationCache.CustomClassificationCodeNames.Count; while (standardPass <= 10) { // Create a classification, if it is not set. string classificationCodeFieldName = null; if (customPass < numCustomCodes) { classificationCodeFieldName = ExporterCacheManager.ClassificationCache.CustomClassificationCodeNames[customPass]; customPass++; if (string.IsNullOrWhiteSpace(classificationCodeFieldName)) { continue; } } else { classificationCodeFieldName = baseClassificationCodeFieldName; if (standardPass > 1) { classificationCodeFieldName += "(" + standardPass + ")"; } standardPass++; } if (ParameterUtil.GetStringValueFromElementOrSymbol(element, classificationCodeFieldName, out paramClassificationCode) == null) { continue; } parseClassificationCode(paramClassificationCode, classificationCodeFieldName, out classificationName, out classificationCode, out classificationDescription); // If classificationName is empty, there is no classification to export. if (String.IsNullOrEmpty(classificationName)) { continue; } IFCAnyHandle classification; if (!ExporterCacheManager.ClassificationCache.ClassificationHandles.TryGetValue(classificationName, out classification)) { IFCClassification savedClassification = new IFCClassification(); if (ExporterCacheManager.ClassificationCache.ClassificationsByName.TryGetValue(classificationName, out savedClassification)) { if (savedClassification.ClassificationEditionDate == null) { IFCAnyHandle editionDate = IFCInstanceExporter.CreateCalendarDate(file, savedClassification.ClassificationEditionDate.Day, savedClassification.ClassificationEditionDate.Month, savedClassification.ClassificationEditionDate.Year); classification = IFCInstanceExporter.CreateClassification(file, savedClassification.ClassificationSource, savedClassification.ClassificationEdition, editionDate, savedClassification.ClassificationName); } else { classification = IFCInstanceExporter.CreateClassification(file, savedClassification.ClassificationSource, savedClassification.ClassificationEdition, null, savedClassification.ClassificationName); } if (!String.IsNullOrEmpty(savedClassification.ClassificationLocation)) { ExporterCacheManager.ClassificationLocationCache.Add(classificationName, savedClassification.ClassificationLocation); } } else { classification = IFCInstanceExporter.CreateClassification(file, "", "", null, classificationName); } ExporterCacheManager.ClassificationCache.ClassificationHandles.Add(classificationName, classification); createdClassification = true; } string location = null; ExporterCacheManager.ClassificationLocationCache.TryGetValue(classificationName, out location); if (!String.IsNullOrEmpty(classificationCode)) { InsertClassificationReference(exporterIFC, file, elemHnd, classificationName, classificationCode, classificationDescription, location); createdClassification = true; } } return(createdClassification); }
/// <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) { 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)); string rebarDescription = NamingUtil.GetDescriptionOverride(rebarElement, null); string rebarObjectType = NamingUtil.GetObjectTypeOverride(rebarElement, NamingUtil.CreateIFCObjectName(exporterIFC, rebarElement)); string rebarTag = NamingUtil.GetTagOverride(rebarElement, NamingUtil.CreateIFCElementId(rebarElement)); const int maxBarGUIDS = IFCReinforcingBarSubElements.BarEnd - IFCReinforcingBarSubElements.BarStart + 1; ElementId categoryId = CategoryUtil.GetSafeCategoryId(rebarElement); IFCAnyHandle originalPlacement = setter.LocalPlacement; double barLength = totalBarLength / rebarQuantity; IList <Curve> baseCurves = GetRebarCenterlineCurves(rebarItem, true, false, false); for (int ii = 0; ii < numberOfBarPositions; ii++) { if (!DoesBarExistAtPosition(rebarItem, ii)) { continue; } int indexForNamingAndGUID = (itemIndex > 0) ? ii + itemIndex : ii + 1; string rebarName = NamingUtil.GetNameOverride(rebarElement, origRebarName + ": " + 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(file, rebarGUID, ExporterCacheManager.OwnerHistoryHandle, rebarName, rebarDescription, rebarObjectType, copyLevelPlacement, prodRep, rebarTag, steelGrade, longitudinalBarNominalDiameter, longitudinalBarCrossSectionArea, barLength, role, null); // 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)); ExporterCacheManager.HandleToElementCache.Register(elemHnd, rebarElement.Id); CategoryUtil.CreateMaterialAssociation(exporterIFC, elemHnd, materialId); } } transaction.Commit(); } return(createdRebars); }
/// <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 ExportGenericElement(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, ProductWrapper productWrapper, IFCExportInfoPair exportType) { if (element == null || geometryElement == null) { return(null); } // Check the intended IFC entity or type name is in the exclude list specified in the UI if (exportType.ExportInstance == IFCEntityType.UnKnown) { exportType.SetValueWithPair(IFCEntityType.IfcBuildingElementProxy, exportType.ValidatedPredefinedType); } if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(exportType.ExportInstance)) { return(null); } // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd); IFCFile file = exporterIFC.GetFile(); IFCAnyHandle instanceHandle = null; using (IFCTransaction tr = new IFCTransaction(file)) { using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd)) { 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(null); } string guid = GUIDUtil.CreateGUID(element); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; IFCAnyHandle localPlacement = ecData.GetLocalPlacement(); IFCAnyHandle styleHandle = null; instanceHandle = FamilyExporterUtil.ExportGenericInstance(exportType, exporterIFC, element, productWrapper, placementSetter, ecData, guid, ownerHistory, representation, exportType.ValidatedPredefinedType, null); if (exportType.ExportType != IFCEntityType.UnKnown) { if (element is FamilyInstance) { FamilySymbol familySymbol = (element as FamilyInstance).Symbol; if (familySymbol != null) { HashSet <IFCAnyHandle> propertySetsOpt = new HashSet <IFCAnyHandle>(); IList <IFCAnyHandle> repMapListOpt = new List <IFCAnyHandle>(); styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, exportType.ValidatedPredefinedType, propertySetsOpt, repMapListOpt, element, familySymbol); } } if (IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle)) { styleHandle = ExporterUtil.CreateGenericTypeFromElement(element, exportType, file, ownerHistory, exportType.ValidatedPredefinedType, productWrapper); } } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle)) { productWrapper.AddElement(element, instanceHandle, placementSetter.LevelInfo, ecData, true, exportType); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle)) { ExporterCacheManager.TypeRelationsCache.Add(styleHandle, instanceHandle); } } } tr.Commit(); } } return(instanceHandle); }
private static int CalculateRequestDataSize(string name) { var dataSize = ClientMessage.HeaderSize; dataSize += ParameterUtil.CalculateDataSize(name); return dataSize; }
/// <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); } // Check the intended IFC entity or type name is in the exclude list specified in the UI Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcReinforcingMesh; if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return(false); } Document doc = sheet.Document; IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, sheet, out overrideContainerHnd); using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, sheet, null, null, overrideContainerId, overrideContainerHnd)) { 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 = NamingUtil.GetFamilyAndTypeName(sheet); IFCAnyHandle localPlacement = ecData.GetLocalPlacement(); 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(exporterIFC, sheet, guid, ownerHistory, localPlacement, prodRep, steelGrade, meshLength, meshWidth, longitudinalBarNominalDiameter, transverseBarNominalDiameter, longitudinalBarCrossSectionArea, transverseBarCrossSectionArea, longitudinalBarSpacing, transverseBarSpacing); IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcReinforcingMesh); 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, exportInfo); CategoryUtil.CreateMaterialAssociation(exporterIFC, fabricSheet, materialId); } } tr.Commit(); return(true); } }
/// <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, IFCExportInfoPair exportType, string ifcEnumType, ProductWrapper productWrapper) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { // CQ_TODO: Clean up this code by at least factoring it out. // If we are exporting a duct segment, we may need to split it into parts by level. Create a list of ranges. IList <ElementId> levels = new List <ElementId>(); IList <IFCRange> ranges = new List <IFCRange>(); // We will not split duct segments if the assemblyId is set, as we would like to keep the original duct segment // associated with the assembly, on the level of the assembly. if ((exportType.ExportType == IFCEntityType.IfcDuctSegmentType) && (ExporterCacheManager.ExportOptionsCache.WallAndColumnSplitting) && (element.AssemblyInstanceId == ElementId.InvalidElementId)) { LevelUtil.CreateSplitLevelRangesForElement(exporterIFC, exportType, element, out levels, out ranges); } int numPartsToExport = ranges.Count; { ElementId catId = CategoryUtil.GetSafeCategoryId(element); BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow); if (0 == numPartsToExport) { // 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)) { IFCAnyHandle localPlacementToUse = setter.LocalPlacement; BodyData bodyData = null; using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData()) { extraParams.SetLocalPlacement(localPlacementToUse); IFCAnyHandle productRepresentation = RepresentationUtil.CreateAppropriateProductDefinitionShape( exporterIFC, element, catId, geometryElement, bodyExporterOptions, null, extraParams, out bodyData); if (IFCAnyHandleUtil.IsNullOrHasNoValue(productRepresentation)) { extraParams.ClearOpenings(); return(false); } ExportAsMappedItem(exporterIFC, element, file, exportType, ifcEnumType, extraParams, setter, localPlacementToUse, productRepresentation, productWrapper); } } } else { for (int ii = 0; ii < numPartsToExport; ii++) { // Check for containment override IFCAnyHandle overrideContainerHnd = null; ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd); using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, null, levels[ii], overrideContainerHnd)) { IFCAnyHandle localPlacementToUse = setter.LocalPlacement; using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData()) { SolidMeshGeometryInfo solidMeshCapsule = GeometryUtil.GetClippedSolidMeshGeometry(geometryElement, ranges[ii]); IList <Solid> solids = solidMeshCapsule.GetSolids(); IList <Mesh> polyMeshes = solidMeshCapsule.GetMeshes(); IList <GeometryObject> geomObjects = FamilyExporterUtil.RemoveInvisibleSolidsAndMeshes(element.Document, exporterIFC, ref solids, ref polyMeshes); if (geomObjects.Count == 0 && (solids.Count > 0 || polyMeshes.Count > 0)) { return(false); } bool tryToExportAsExtrusion = (!exporterIFC.ExportAs2x2 || (exportType.ExportInstance == IFCEntityType.IfcColumn)); if (exportType.ExportInstance == IFCEntityType.IfcColumn) { extraParams.PossibleExtrusionAxes = IFCExtrusionAxes.TryZ; } else { extraParams.PossibleExtrusionAxes = IFCExtrusionAxes.TryXYZ; } BodyData bodyData = null; if (geomObjects.Count > 0) { bodyData = BodyExporter.ExportBody(exporterIFC, element, catId, ElementId.InvalidElementId, geomObjects, bodyExporterOptions, extraParams); } else { IList <GeometryObject> exportedGeometries = new List <GeometryObject>(); exportedGeometries.Add(geometryElement); bodyData = BodyExporter.ExportBody(exporterIFC, element, catId, ElementId.InvalidElementId, exportedGeometries, bodyExporterOptions, extraParams); } List <IFCAnyHandle> bodyReps = new List <IFCAnyHandle>(); bodyReps.Add(bodyData.RepresentationHnd); IFCAnyHandle productRepresentation = IFCInstanceExporter.CreateProductDefinitionShape(exporterIFC.GetFile(), null, null, bodyReps); if (IFCAnyHandleUtil.IsNullOrHasNoValue(productRepresentation)) { extraParams.ClearOpenings(); return(false); } ExportAsMappedItem(exporterIFC, element, file, exportType, ifcEnumType, extraParams, setter, localPlacementToUse, productRepresentation, productWrapper); } } } } } tr.Commit(); } return(true); }
/// <summary> /// Process to create element quantity. /// </summary> /// <param name="file"> /// The IFC file. /// </param> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="extrusionCreationData"> /// The IFCExtrusionCreationData. /// </param> /// <param name="element"> /// The element of which this property is created for. /// </param> /// <param name="elementType"> /// The element type of which this quantity is created for. /// </param> /// <returns> /// Then created quantity handle. /// </returns> public IFCAnyHandle ProcessEntry(IFCFile file, ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType) { bool useProperty = (!String.IsNullOrEmpty(RevitParameterName)) || (RevitBuiltInParameter != BuiltInParameter.INVALID); bool success = false; double val = 0; if (useProperty) { success = (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, RevitParameterName, out val) != null); if (!success && RevitBuiltInParameter != BuiltInParameter.INVALID) { success = (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, RevitBuiltInParameter, out val) != null); } if (success) // factor in the scale factor for all the parameters depending of the data type to get the correct value { switch (m_QuantityType) { case QuantityType.PositiveLength: val = UnitUtil.ScaleLength(val); break; case QuantityType.Area: val = UnitUtil.ScaleArea(val); break; case QuantityType.Volume: val = UnitUtil.ScaleVolume(val); break; default: break; } } } if (PropertyCalculator != null && !success) { success = PropertyCalculator.Calculate(exporterIFC, extrusionCreationData, element, elementType); if (success) { val = PropertyCalculator.GetDoubleValue(); } } IFCAnyHandle quantityHnd = null; if (success) { switch (QuantityType) { case QuantityType.PositiveLength: quantityHnd = IFCInstanceExporter.CreateQuantityLength(file, PropertyName, MethodOfMeasurement, null, val); break; case QuantityType.Area: quantityHnd = IFCInstanceExporter.CreateQuantityArea(file, PropertyName, MethodOfMeasurement, null, val); break; case QuantityType.Volume: quantityHnd = IFCInstanceExporter.CreateQuantityVolume(file, PropertyName, MethodOfMeasurement, null, val); break; default: throw new InvalidOperationException("Missing case!"); } } return(quantityHnd); }
/// <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) { Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcRoof; if (element is Wall || element is CurtainSystem || IsLegacyCurtainElement(element)) { elementClassTypeEnum = Common.Enums.IFCEntityType.IfcCurtainWall; } else if (element is RoofBase) { elementClassTypeEnum = Common.Enums.IFCEntityType.IfcRoof; } if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return; } 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; // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd); setter = PlacementSetter.Create(exporterIFC, element, null, orientationTrf, overrideContainerId, overrideContainerHnd); localPlacement = setter.LocalPlacement; string objectType = NamingUtil.CreateIFCObjectName(exporterIFC, element); IFCAnyHandle prodRepHnd = null; IFCAnyHandle elemHnd = null; string elemGUID = GUIDUtil.CreateGUID(element); if (element is Wall || element is CurtainSystem || IsLegacyCurtainElement(element)) { elemHnd = IFCInstanceExporter.CreateCurtainWall(exporterIFC, element, elemGUID, ownerHistory, localPlacement, prodRepHnd, null); } else if (element is RoofBase) { //need to convert the string to enum string ifcEnumType = ExporterUtil.GetIFCTypeFromExportTable(exporterIFC, element); //ifcEnumType = IFCValidateEntry.GetValidIFCPredefinedType(element, ifcEnumType); elemHnd = IFCInstanceExporter.CreateRoof(exporterIFC, element, elemGUID, ownerHistory, localPlacement, prodRepHnd, ifcEnumType); } else { return; } if (IFCAnyHandleUtil.IsNullOrHasNoValue(elemHnd)) { return; } wrapper.AddElement(element, elemHnd, setter, null, true, null); 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(); } } } }
/// <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); } // Check the intended IFC entity or type name is in the exclude list specified in the UI Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcCovering; if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return(false); } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { // Check for containment override IFCAnyHandle overrideContainer = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainer); using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainer)) { 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; IFCAnyHandle localPlacement = ecData.GetLocalPlacement(); string ifcType = "Wrapping"; IFCAnyHandle ductLining = IFCInstanceExporter.CreateCovering(exporterIFC, element, guid, ownerHistory, localPlacement, representation, ifcType); ExporterCacheManager.ElementToHandleCache.Register(element.Id, ductLining); IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcCovering, ifcType); productWrapper.AddElement(element, ductLining, placementSetter.LevelInfo, ecData, true, exportInfo); ElementId matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, element); CategoryUtil.CreateMaterialAssociation(exporterIFC, ductLining, matId); } } tr.Commit(); return(true); } }
/// <summary> /// Exports an element to IfcPile. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="element">The element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="ifcEnumType">The string value represents the IFC type.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void ExportPile(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, string ifcEnumType, ProductWrapper productWrapper) { // NOTE: We expect to incorporate this code into the generic FamilyInstanceExporter at some point. // export parts or not bool exportParts = PartExporter.CanExportParts(element); if (exportParts && !PartExporter.CanExportElementInPartExport(element, element.LevelId, false)) { 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); IFCAnyHandle prodRep = null; ElementId matId = ElementId.InvalidElementId; if (!exportParts) { ElementId catId = CategoryUtil.GetSafeCategoryId(element); matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(geometryElement, exporterIFC, element); BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow); StructuralMemberAxisInfo axisInfo = StructuralMemberExporter.GetStructuralMemberAxisTransform(element); if (axisInfo != null) { ecData.CustomAxis = axisInfo.AxisDirection; ecData.PossibleExtrusionAxes = IFCExtrusionAxes.TryCustom; } else { ecData.PossibleExtrusionAxes = IFCExtrusionAxes.TryZ; } prodRep = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC, element, catId, geometryElement, bodyExporterOptions, null, ecData, true); if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodRep)) { ecData.ClearOpenings(); return; } } string instanceGUID = GUIDUtil.CreateGUID(element); IFCExportInfoPair exportInfo = new IFCExportInfoPair(Common.Enums.IFCEntityType.IfcPile, ifcEnumType); IFCAnyHandle pile = IFCInstanceExporter.CreatePile(exporterIFC, element, instanceGUID, ExporterCacheManager.OwnerHistoryHandle, ecData.GetLocalPlacement(), prodRep, ifcEnumType, null); // TODO: to allow shared geometry for Piles. For now, Pile export will not use shared geometry if (exportInfo.ExportType != Common.Enums.IFCEntityType.UnKnown) { IFCAnyHandle type = ExporterUtil.CreateGenericTypeFromElement(element, exportInfo, file, ExporterCacheManager.OwnerHistoryHandle, exportInfo.ValidatedPredefinedType, productWrapper); ExporterCacheManager.TypeRelationsCache.Add(type, pile); } if (exportParts) { PartExporter.ExportHostPart(exporterIFC, element, pile, productWrapper, setter, setter.LocalPlacement, null); } else { if (matId != ElementId.InvalidElementId) { CategoryUtil.CreateMaterialAssociation(exporterIFC, pile, matId); } } productWrapper.AddElement(element, pile, setter, ecData, true, exportInfo); OpeningUtil.CreateOpeningsIfNecessary(pile, element, ecData, null, exporterIFC, ecData.GetLocalPlacement(), setter, productWrapper); } } tr.Commit(); } }