/// <summary> /// Creates a shape representation and register it to shape representation layer. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="identifier">The identifier for the representation.</param> /// <param name="representationType">The type handle for the representation.</param> /// <param name="items">Collection of geometric representation items that are defined for this representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateShapeRepresentation(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, string identifier, string representationType, ISet<IFCAnyHandle> items) { IFCAnyHandle newShapeRepresentation = CreateBaseShapeRepresentation(exporterIFC, contextOfItems, identifier, representationType, items); if (IFCAnyHandleUtil.IsNullOrHasNoValue(newShapeRepresentation)) return newShapeRepresentation; // Search for old "IFCCadLayer" or new "IfcPresentationLayer". string ifcCADLayer = null; if ((ParameterUtil.GetStringValueFromElementOrSymbol(element, "IFCCadLayer", out ifcCADLayer) == null) || string.IsNullOrWhiteSpace(ifcCADLayer)) { if ((ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcPresentationLayer", out ifcCADLayer) == null) || string.IsNullOrWhiteSpace(ifcCADLayer)) { ifcCADLayer = ExporterStateManager.GetCurrentCADLayerOverride(); } } // We are using the DWG export layer table to correctly map category to DWG layer for the // IfcPresentationLayerAsssignment, if it is not overridden. if (!string.IsNullOrWhiteSpace(ifcCADLayer)) ExporterCacheManager.PresentationLayerSetCache.AddRepresentationToLayer(ifcCADLayer, newShapeRepresentation); else exporterIFC.RegisterShapeForPresentationLayer(element, categoryId, newShapeRepresentation); return newShapeRepresentation; }
/// <summary> /// Checks if an element has the IfcExportAs variable set to "DontExport". /// </summary> /// <param name="element">The element.</param> /// <returns>True if the element has the IfcExportAs variable set to "DontExport".</returns> public static bool IsIFCExportAsSetToDontExport(Element element, out string elementClassName) { const string exportAsEntity = "IFCExportAs"; if (ParameterUtil.GetStringValueFromElementOrSymbol(element, exportAsEntity, out elementClassName) != null) { if (CompareAlphaOnly(elementClassName, "DONTEXPORT")) { return(true); } } return(false); }
/// <summary> /// Checks if element should be exported using a variety of different checks. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="element">The element.</param> /// <param name="allowSeparateOpeningExport">True if IfcOpeningElement is allowed to be exported.</param> /// <returns>True if the element should be exported, false otherwise.</returns> /// <remarks>There are some inefficiencies here, as we later check IfcExportAs in other contexts. We should attempt to get the value only once.</remarks> public static bool ShouldElementBeExported(ExporterIFC exporterIFC, Element element, bool allowSeparateOpeningExport) { // Allow the ExporterStateManager to say that an element should be exported regardless of settings. if (ExporterStateManager.CanExportElementOverride()) { return(true); } // Check to see if the category should be exported. This overrides the IfcExportAs parameter. if (!ShouldCategoryBeExported(exporterIFC, element, allowSeparateOpeningExport)) { return(false); } string exportAsEntity = "IFCExportAs"; string elementClassName; if (ParameterUtil.GetStringValueFromElementOrSymbol(element, exportAsEntity, out elementClassName) != null) { string enumTypeValue = string.Empty; ExporterUtil.ExportEntityAndPredefinedType(elementClassName, out elementClassName, out enumTypeValue); if (CompareAlphaOnly(elementClassName, "DONTEXPORT")) { return(false); } // Check whether the intended Entity type is inside the export exclusion set Common.Enums.IFCEntityType elementClassTypeEnum; if (Enum.TryParse <Common.Enums.IFCEntityType>(elementClassName, out elementClassTypeEnum)) { if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return(false); } } } return(true); }
private void CalculateDoorWindowInformation(ExporterIFC exporterIFC, FamilyInstance famInst, ElementId overrideLevelId, Transform trf) { IFCFile file = exporterIFC.GetFile(); if (ExportingDoor) { string doorOperationType = null; Element doorType = famInst.Document.GetElement(famInst.GetTypeId()); if (doorType != null) { // Look at the "Operation" override first, then the built-in parameter. ParameterUtil.GetStringValueFromElementOrSymbol(doorType, "Operation", out doorOperationType); if (!string.IsNullOrWhiteSpace(doorOperationType)) { ParameterUtil.GetStringValueFromElement(doorType, BuiltInParameter.DOOR_OPERATION_TYPE, out doorOperationType); } } DoorOperationTypeString = "NOTDEFINED"; if (!string.IsNullOrWhiteSpace(doorOperationType)) { Type enumType = null; if (ExporterCacheManager.ExportOptionsCache.ExportAs4) { enumType = typeof(Toolkit.IFC4.IFCDoorStyleOperation); } else { enumType = typeof(Toolkit.IFCDoorStyleOperation); } foreach (Enum ifcDoorStyleOperation in Enum.GetValues(enumType)) { string enumAsString = ifcDoorStyleOperation.ToString(); if (NamingUtil.IsEqualIgnoringCaseSpacesAndUnderscores(enumAsString, doorOperationType)) { DoorOperationTypeString = enumAsString; break; } } } if (DoorOperationTypeString == "NOTDEFINED") { // We are going to try to guess the hinge placement. DoorOperationTypeString = CalculateDoorOperationStyle(famInst); } if (FlippedX ^ FlippedY) { DoorOperationTypeString = ReverseDoorStyleOperation(DoorOperationTypeString); } if (String.Compare(DoorOperationTypeString, "USERDEFINED", true) == 0) { string userDefinedOperationType; ParameterUtil.GetStringValueFromElementOrSymbol(doorType, "UserDefinedOperationType", out userDefinedOperationType); if (!string.IsNullOrEmpty(userDefinedOperationType)) { UserDefinedOperationType = userDefinedOperationType; } else { DoorOperationTypeString = "NOTDEFINED"; //re-set to NotDefined if operation type is set to UserDefined but the userDefinedOperationType parameter is empty! } } } if (HasRealWallHost) { // do hingeside calculation Wall wall = HostObject as Wall; PosHingeSide = true; BoundingBoxXYZ famBBox = null; Options options = GeometryUtil.GetIFCExportGeometryOptions(); GeometryElement geomElement = famInst.GetOriginalGeometry(options); if (geomElement != null) { famBBox = geomElement.GetBoundingBox(); } if (famBBox != null) { XYZ bboxCtr = trf.OfPoint((famBBox.Min + famBBox.Max) / 2.0); Curve curve = WallExporter.GetWallAxis(wall); XYZ wallZDir = WallExporter.GetWallHeightDirection(wall); // famInst.HostParameter will fail if FamilyPlacementType is WorkPlaneBased, regardless of whether or not the reported host is a Wall. // In this case, just use the start parameter of the curve. bool hasHostParameter = famInst.Symbol.Family.FamilyPlacementType != FamilyPlacementType.WorkPlaneBased; double param = hasHostParameter ? famInst.HostParameter : curve.GetEndParameter(0); Transform wallTrf = curve.ComputeDerivatives(param, false); XYZ wallOrig = wallTrf.Origin; XYZ wallXDir = wallTrf.BasisX; XYZ wallYDir = wallZDir.CrossProduct(wallXDir); double eps = MathUtil.Eps(); bboxCtr -= wallOrig; PosHingeSide = (bboxCtr.DotProduct(wallYDir) > -eps); XYZ famInstYDir = trf.BasisY; FlippedSymbol = (PosHingeSide != (wallYDir.DotProduct(famInstYDir) > -eps)); } } }
/// <summary> /// Collect information about material layer. /// For IFC4RV Architectural exchange, it will generate IfcMatrialConstituentSet along with the relevant IfcShapeAspect and the width in the quantityset /// For IFC4RV Structural exchange, it will generate multiple components as IfcBuildingElementPart for each layer /// For others IfcMaterialLayer will be created /// </summary> private void CollectMaterialLayerSet() { ElementId typeElemId = m_Element.GetTypeId(); MaterialIds = new List <Tuple <ElementId, string, double> >(); IFCAnyHandle materialLayerSet = ExporterCacheManager.MaterialSetCache.FindLayerSet(typeElemId); // Roofs with no components are only allowed one material. We will arbitrarily choose the thickest material. PrimaryMaterialHandle = ExporterCacheManager.MaterialSetCache.FindPrimaryMaterialHnd(typeElemId); if (IFCAnyHandleUtil.IsNullOrHasNoValue(materialLayerSet)) { List <double> widths = new List <double>(); List <MaterialFunctionAssignment> functions = new List <MaterialFunctionAssignment>(); HostObjAttributes hostObjAttr = m_Element.Document.GetElement(typeElemId) as HostObjAttributes; if (hostObjAttr == null) { // It does not have the HostObjAttribute (where we will get the compound structure for material layer set. // We will define a single material instead and create the material layer set of this single material if there is enough information (At least Material id and thickness) FamilyInstance familyInstance = m_Element as FamilyInstance; if (familyInstance == null) { return; } FamilySymbol familySymbol = familyInstance.Symbol; ICollection <ElementId> famMatIds = familySymbol.GetMaterialIds(false); if (famMatIds.Count == 0) { // For some reason Plate type may not return any Material id ElementId baseMatId = CategoryUtil.GetBaseMaterialIdForElement(m_Element); Material material = m_Element.Document.GetElement(baseMatId) as Material; if (material == null) { return; } string layerName = NamingUtil.GetOverrideStringValue(material, "IfcMaterialLayer.Name", material.Name); double matWidth = 0.0; Parameter thicknessPar = familySymbol.get_Parameter(BuiltInParameter.CURTAIN_WALL_SYSPANEL_THICKNESS); if (thicknessPar != null) { matWidth = thicknessPar.AsDouble(); } widths.Add(matWidth); if (baseMatId != ElementId.InvalidElementId) { MaterialIds.Add(new Tuple <ElementId, string, double>(baseMatId, layerName, matWidth)); } // How to get the thickness? For CurtainWall Panel (PanelType), there is a builtin parameter CURTAINWALL_SYSPANEL_THICKNESS functions.Add(MaterialFunctionAssignment.None); } else { foreach (ElementId matid in famMatIds) { // How to get the thickness? For CurtainWall Panel (PanelType), there is a builtin parameter CURTAINWALL_SYSPANEL_THICKNESS Parameter thicknessPar = familySymbol.get_Parameter(BuiltInParameter.CURTAIN_WALL_SYSPANEL_THICKNESS); double matWidth = 0.0; if (thicknessPar == null) { matWidth = ParameterUtil.GetSpecialThicknessParameter(familySymbol); } else { matWidth = thicknessPar.AsDouble(); } if (MathUtil.IsAlmostZero(matWidth)) { continue; } widths.Add(matWidth); ElementId baseMatId = CategoryUtil.GetBaseMaterialIdForElement(m_Element); if (matid != ElementId.InvalidElementId) { Material material = m_Element.Document.GetElement(matid) as Material; if (material != null) { string layerName = NamingUtil.GetOverrideStringValue(material, "IfcMaterialLayer.Name", material.Name); MaterialIds.Add(new Tuple <ElementId, string, double>(matid, layerName, matWidth)); } } else { MaterialIds.Add(new Tuple <ElementId, string, double>(baseMatId, null, matWidth)); } functions.Add(MaterialFunctionAssignment.None); } } } else { ElementId baseMatId = CategoryUtil.GetBaseMaterialIdForElement(m_Element); CompoundStructure cs = hostObjAttr.GetCompoundStructure(); if (cs != null) { double scaledOffset = 0.0, scaledWallWidth = 0.0, wallHeight = 0.0; Wall wall = m_Element as Wall; if (wall != null) { scaledWallWidth = UnitUtil.ScaleLength(wall.Width); scaledOffset = -scaledWallWidth / 2.0; BoundingBoxXYZ boundingBox = wall.get_BoundingBox(null); if (boundingBox != null) { wallHeight = boundingBox.Max.Z - boundingBox.Min.Z; } } //TODO: Vertically compound structures are not yet supported by export. if (!cs.IsVerticallyHomogeneous() && !MathUtil.IsAlmostZero(wallHeight)) { cs = cs.GetSimpleCompoundStructure(wallHeight, wallHeight / 2.0); } for (int ii = 0; ii < cs.LayerCount; ++ii) { double matWidth = cs.GetLayerWidth(ii); //if (MathUtil.IsAlmostZero(matWidth)) // continue; ElementId matId = cs.GetMaterialId(ii); if (matId != ElementId.InvalidElementId) { Material material = m_Element.Document.GetElement(matId) as Material; if (material != null) { string layerName = NamingUtil.GetOverrideStringValue(material, "IfcMaterialLayer.Name", material.Name); MaterialIds.Add(new Tuple <ElementId, string, double>(matId, layerName, matWidth)); } } else { MaterialIds.Add(new Tuple <ElementId, string, double>(baseMatId, null, matWidth)); } widths.Add(matWidth); // save layer function into ProductWrapper, // it's used while exporting "Function" of Pset_CoveringCommon functions.Add(cs.GetLayerFunction(ii)); } } if (MaterialIds.Count == 0) { double matWidth = cs != null?cs.GetWidth() : 0.0; widths.Add(matWidth); if (baseMatId != ElementId.InvalidElementId) { Material material = m_Element.Document.GetElement(baseMatId) as Material; if (material != null) { string layerName = NamingUtil.GetOverrideStringValue(material, "IfcMaterialLayer.Name", material.Name); MaterialIds.Add(new Tuple <ElementId, string, double>(baseMatId, layerName, matWidth)); } } functions.Add(MaterialFunctionAssignment.None); } } if (m_ProductWrapper != null) { m_ProductWrapper.ClearFinishMaterials(); } // We can't create IfcMaterialLayers without creating an IfcMaterialLayerSet. So we will simply collate here. IList <IFCAnyHandle> materialHnds = new List <IFCAnyHandle>(); IList <int> widthIndices = new List <int>(); double thickestLayer = 0.0; for (int ii = 0; ii < MaterialIds.Count; ++ii) { // Require positive width for IFC2x3 and before, and non-negative width for IFC4. if (widths[ii] < -MathUtil.Eps()) { continue; } bool almostZeroWidth = MathUtil.IsAlmostZero(widths[ii]); if (!ExporterCacheManager.ExportOptionsCache.ExportAs4 && almostZeroWidth) { continue; } if (almostZeroWidth) { widths[ii] = 0.0; } IFCAnyHandle materialHnd = CategoryUtil.GetOrCreateMaterialHandle(m_ExporterIFC, MaterialIds[ii].Item1); if (PrimaryMaterialHandle == null || (widths[ii] > thickestLayer)) { PrimaryMaterialHandle = materialHnd; thickestLayer = widths[ii]; } widthIndices.Add(ii); materialHnds.Add(materialHnd); if ((m_ProductWrapper != null) && (functions[ii] == MaterialFunctionAssignment.Finish1 || functions[ii] == MaterialFunctionAssignment.Finish2)) { m_ProductWrapper.AddFinishMaterial(materialHnd); } } int numLayersToCreate = widthIndices.Count; if (numLayersToCreate == 0) { MaterialLayerSetHandle = materialLayerSet; return; } // If it is a single material, check single material override (only IfcMaterial without IfcMaterialLayerSet with only 1 member) if (numLayersToCreate == 1 && ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { string paramValue; ParameterUtil.GetStringValueFromElementOrSymbol(m_Element, "IfcSingleMaterialOverride", out paramValue); if (!string.IsNullOrEmpty(paramValue)) { IFCAnyHandle singleMaterialOverrideHnd = IFCInstanceExporter.CreateMaterial(m_ExporterIFC.GetFile(), paramValue, null, null); ExporterCacheManager.MaterialHandleCache.Register(MaterialIds[0].Item1, singleMaterialOverrideHnd); MaterialLayerSetHandle = singleMaterialOverrideHnd; return; } } IFCFile file = m_ExporterIFC.GetFile(); Document document = ExporterCacheManager.Document; IList <IFCAnyHandle> layers = new List <IFCAnyHandle>(numLayersToCreate); IList <Tuple <string, IFCAnyHandle> > layerWidthQuantities = new List <Tuple <string, IFCAnyHandle> >(); HashSet <string> layerNameUsed = new HashSet <string>(); double totalWidth = 0.0; for (int ii = 0; ii < numLayersToCreate; ii++) { int widthIndex = widthIndices[ii]; double scaledWidth = UnitUtil.ScaleLength(widths[widthIndex]); string layerName = "Layer"; string description = null; string category = null; int? priority = null; IFCLogical?isVentilated = null; int isVentilatedValue; Material material = document.GetElement(MaterialIds[ii].Item1) as Material; if (material != null) { if (ParameterUtil.GetIntValueFromElement(material, "IfcMaterialLayer.IsVentilated", out isVentilatedValue) != null) { if (isVentilatedValue == 0) { isVentilated = IFCLogical.False; } else if (isVentilatedValue == 1) { isVentilated = IFCLogical.True; } } if (ExporterCacheManager.ExportOptionsCache.ExportAs4) { layerName = MaterialIds[ii].Item2; if (string.IsNullOrEmpty(layerName)) { layerName = "Layer"; } // Ensure layer name is unique layerName = NamingUtil.GetUniqueNameWithinSet(layerName, ref layerNameUsed); description = NamingUtil.GetOverrideStringValue(material, "IfcMaterialLayer.Description", IFCAnyHandleUtil.GetStringAttribute(materialHnds[ii], "Description")); category = NamingUtil.GetOverrideStringValue(material, "IfcMaterialLayer.Category", IFCAnyHandleUtil.GetStringAttribute(materialHnds[ii], "Category")); int priorityValue; if (ParameterUtil.GetIntValueFromElement(material, "IfcMaterialLayer.Priority", out priorityValue) != null) { priority = priorityValue; } } } if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { // Skip component that has zero width (the will be no geometry associated to it if (MathUtil.IsAlmostZero(scaledWidth)) { continue; } IFCAnyHandle materialConstituent = IFCInstanceExporter.CreateMaterialConstituent(file, materialHnds[ii], name: layerName, description: description, category: category); layers.Add(materialConstituent); IFCAnyHandle layerQtyHnd = IFCInstanceExporter.CreateQuantityLength(file, "Width", description, null, scaledWidth); totalWidth += scaledWidth; layerWidthQuantities.Add(new Tuple <string, IFCAnyHandle>(layerName, layerQtyHnd)); } else { IFCAnyHandle materialLayer = IFCInstanceExporter.CreateMaterialLayer(file, materialHnds[ii], scaledWidth, isVentilated, name: layerName, description: description, category: category, priority: priority); layers.Add(materialLayer); } } if (layers.Count > 0) { Element type = document.GetElement(typeElemId); string layerSetName = NamingUtil.GetOverrideStringValue(type, "IfcMaterialLayerSet.Name", m_ExporterIFC.GetFamilyName()); string layerSetDesc = NamingUtil.GetOverrideStringValue(type, "IfcMaterialLayerSet.Description", null); if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { HashSet <IFCAnyHandle> constituents = new HashSet <IFCAnyHandle>(layers); MaterialLayerSetHandle = IFCInstanceExporter.CreateMaterialConstituentSet(file, constituents, name: layerSetName, description: layerSetDesc); foreach (Tuple <string, IFCAnyHandle> layerWidthQty in layerWidthQuantities) { LayerQuantityWidthHnd.Add(IFCInstanceExporter.CreatePhysicalComplexQuantity(file, layerWidthQty.Item1, null, new HashSet <IFCAnyHandle>() { layerWidthQty.Item2 }, "Layer", null, null)); } // Finally create the total width as a quantity LayerQuantityWidthHnd.Add(IFCInstanceExporter.CreateQuantityLength(file, "Width", null, null, totalWidth)); } else { MaterialLayerSetHandle = IFCInstanceExporter.CreateMaterialLayerSet(file, layers, layerSetName, layerSetDesc); } ExporterCacheManager.MaterialSetCache.RegisterLayerSet(typeElemId, MaterialLayerSetHandle, this); } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(PrimaryMaterialHandle)) { ExporterCacheManager.MaterialSetCache.RegisterPrimaryMaterialHnd(typeElemId, PrimaryMaterialHandle); } } else { MaterialLayerSetHandle = materialLayerSet; MaterialLayerSetInfo mlsInfo = ExporterCacheManager.MaterialSetCache.FindMaterialLayerSetInfo(typeElemId); if (mlsInfo != null) { MaterialIds = mlsInfo.MaterialIds; PrimaryMaterialHandle = mlsInfo.PrimaryMaterialHandle; LayerQuantityWidthHnd = mlsInfo.LayerQuantityWidthHnd; } } return; }