/// <summary> /// Return the materials' names and thicknesses if the object is created with IFCMaterialLayerSetUsage information. /// The thickness is returned as a string followed by its unit /// If the object is not created with IFCMaterialLayerSetUsage information, then only the materials' names are returned /// </summary> /// <returns>A list in which each entry is the material's names followed by their thicknesses if the thicknesses are available</returns> public IList <string> GetMaterialsNamesAndThicknesses() { IList <string> result = new List <string>(); string thickness = null; string name = null; // If this object is created with IFCMaterialLayerSetUsage information // then the material layer thickness will be added after the name of each layer. if (MaterialSelect is IFCMaterialLayerSetUsage) { IFCMaterialLayerSet materialLayerSet = (MaterialSelect as IFCMaterialLayerSetUsage).MaterialLayerSet; IList <IFCMaterialLayer> materialLayers; IFCMaterial material; if (materialLayerSet != null) { materialLayers = materialLayerSet.MaterialLayers; } else { materialLayers = new List <IFCMaterialLayer>(); } foreach (IFCMaterialLayer materialLayer in materialLayers) { if (materialLayer == null) { continue; } material = materialLayer.Material; if (material == null || string.IsNullOrWhiteSpace(material.Name)) { continue; } name = material.Name; thickness = IFCUnitUtil.FormatLengthAsString(materialLayer.LayerThickness); result.Add(name + ": " + thickness); } } else { IList <IFCMaterial> materials = GetMaterials(); foreach (IFCMaterial material in materials) { name = material.Name; if (string.IsNullOrWhiteSpace(name)) { continue; } result.Add(name); } } return(result); }
/// <summary> /// Processes an IfcMaterialLayerSet entity. /// </summary> /// <param name="ifcMaterialLayerSet">The IfcMaterialLayerSet handle.</param> /// <returns>The IFCMaterialLayerSet object.</returns> public static IFCMaterialLayerSet ProcessIFCMaterialLayerSet(IFCAnyHandle ifcMaterialLayerSet) { if (IFCAnyHandleUtil.IsNullOrHasNoValue(ifcMaterialLayerSet)) { Importer.TheLog.LogNullError(IFCEntityType.IfcMaterialLayerSet); return(null); } IFCEntity materialLayerSet; if (!IFCImportFile.TheFile.EntityMap.TryGetValue(ifcMaterialLayerSet.StepId, out materialLayerSet)) { materialLayerSet = new IFCMaterialLayerSet(ifcMaterialLayerSet); } return(materialLayerSet as IFCMaterialLayerSet); }
protected override void Process(IFCAnyHandle ifcMaterialLayerSetUsage) { base.Process(ifcMaterialLayerSetUsage); IFCAnyHandle ifcMaterialLayerSet = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcMaterialLayerSetUsage, "ForLayerSet", true); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(ifcMaterialLayerSet)) { MaterialLayerSet = IFCMaterialLayerSet.ProcessIFCMaterialLayerSet(ifcMaterialLayerSet); } string directionAsString = IFCAnyHandleUtil.GetEnumerationAttribute(ifcMaterialLayerSetUsage, "LayerSetDirection"); if (directionAsString == null) { Direction = IFCLayerSetDirection.Axis3; IFCImportFile.TheLog.LogWarning(ifcMaterialLayerSetUsage.StepId, "No LayerSetDirection defined, defaulting to Axis3.", false); } else { Direction = (IFCLayerSetDirection)Enum.Parse(typeof(IFCLayerSetDirection), directionAsString, true); } string directionSenseAsString = IFCAnyHandleUtil.GetEnumerationAttribute(ifcMaterialLayerSetUsage, "DirectionSense"); if (directionSenseAsString == null) { DirectionSense = IFCDirectionSense.Positive; IFCImportFile.TheLog.LogWarning(ifcMaterialLayerSetUsage.StepId, "No DirectionSense defined, defaulting to Positive.", false); } else { DirectionSense = (IFCDirectionSense)Enum.Parse(typeof(IFCDirectionSense), directionSenseAsString, true); } bool found = false; Offset = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(ifcMaterialLayerSetUsage, "OffsetFromReferenceLine", out found); if (!found) { IFCImportFile.TheLog.LogWarning(ifcMaterialLayerSetUsage.StepId, "No Offset defined, defaulting to 0.", false); } }
/// <summary> /// Processes IfcRelAssociatesMaterial. /// </summary> /// <param name="ifcRelAssociatesMaterial">The IfcRelAssociatesMaterial handle.</param> void ProcessIFCRelAssociatesMaterial(IFCAnyHandle ifcRelAssociatesMaterial) { IFCAnyHandle ifcMaterialSelect = IFCAnyHandleUtil.GetInstanceAttribute(ifcRelAssociatesMaterial, "RelatingMaterial"); if (IFCAnyHandleUtil.IsNullOrHasNoValue(ifcMaterialSelect)) { IFCImportFile.TheLog.LogNullError(IFCEntityType.IfcRelAssociatesMaterial); return; } // Deal with various types of IFCMaterialSelect. if (IFCAnyHandleUtil.IsSubTypeOf(ifcMaterialSelect, IFCEntityType.IfcMaterial)) { MaterialSelect = IFCMaterial.ProcessIFCMaterial(ifcMaterialSelect); } else if (IFCAnyHandleUtil.IsSubTypeOf(ifcMaterialSelect, IFCEntityType.IfcMaterialLayer)) { MaterialSelect = IFCMaterialLayer.ProcessIFCMaterialLayer(ifcMaterialSelect); } else if (IFCAnyHandleUtil.IsSubTypeOf(ifcMaterialSelect, IFCEntityType.IfcMaterialLayerSet)) { MaterialSelect = IFCMaterialLayerSet.ProcessIFCMaterialLayerSet(ifcMaterialSelect); } else if (IFCAnyHandleUtil.IsSubTypeOf(ifcMaterialSelect, IFCEntityType.IfcMaterialLayerSetUsage)) { MaterialSelect = IFCMaterialLayerSetUsage.ProcessIFCMaterialLayerSetUsage(ifcMaterialSelect); } else if (IFCAnyHandleUtil.IsSubTypeOf(ifcMaterialSelect, IFCEntityType.IfcMaterialList)) { MaterialSelect = IFCMaterialList.ProcessIFCMaterialList(ifcMaterialSelect); } else { IFCImportFile.TheLog.LogUnhandledSubTypeError(ifcMaterialSelect, "IfcMaterialSelect", false); } }
protected override void Process(IFCAnyHandle ifcMaterialLayerSetUsage) { base.Process(ifcMaterialLayerSetUsage); IFCAnyHandle ifcMaterialLayerSet = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcMaterialLayerSetUsage, "ForLayerSet", true); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(ifcMaterialLayerSet)) { MaterialLayerSet = IFCMaterialLayerSet.ProcessIFCMaterialLayerSet(ifcMaterialLayerSet); } Direction = IFCEnums.GetSafeEnumerationAttribute(ifcMaterialLayerSetUsage, "LayerSetDirection", IFCLayerSetDirection.Axis3); DirectionSense = IFCEnums.GetSafeEnumerationAttribute(ifcMaterialLayerSetUsage, "DirectionSense", IFCDirectionSense.Positive); bool found = false; Offset = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(ifcMaterialLayerSetUsage, "OffsetFromReferenceLine", out found); if (!found) { Importer.TheLog.LogWarning(ifcMaterialLayerSetUsage.StepId, "No Offset defined, defaulting to 0.", false); } }
// This routine may return null geometry for one of three reasons: // 1. Invalid input. // 2. No IfcMaterialLayerUsage. // 3. The IfcMaterialLayerUsage isn't handled. // If the reason is #1 or #3, we want to warn the user. If it is #2, we don't. Pass back shouldWarn to let the caller know. private IList <GeometryObject> CreateGeometryFromMaterialLayerUsage(IFCImportShapeEditScope shapeEditScope, Transform extrusionPosition, IList <CurveLoop> loops, XYZ extrusionDirection, double currDepth, out ElementId materialId, out bool shouldWarn) { IList <GeometryObject> extrusionSolids = null; materialId = ElementId.InvalidElementId; try { shouldWarn = true; // Invalid input. // Check for valid input. if (shapeEditScope == null || extrusionPosition == null || loops == null || loops.Count() == 0 || extrusionDirection == null || !Application.IsValidThickness(currDepth)) { return(null); } IFCProduct creator = shapeEditScope.Creator; if (creator == null) { return(null); } shouldWarn = false; // Missing, empty, or optimized out IfcMaterialLayerSetUsage - valid reason to stop. IIFCMaterialSelect materialSelect = creator.MaterialSelect; if (materialSelect == null) { return(null); } IFCMaterialLayerSetUsage materialLayerSetUsage = materialSelect as IFCMaterialLayerSetUsage; if (materialLayerSetUsage == null) { return(null); } IFCMaterialLayerSet materialLayerSet = materialLayerSetUsage.MaterialLayerSet; if (materialLayerSet == null) { return(null); } IList <IFCMaterialLayer> materialLayers = materialLayerSet.MaterialLayers; if (materialLayers == null || materialLayers.Count == 0) { return(null); } // Optimization: if there is only one layer, use the standard method, with possibly an overloaded material. ElementId baseMaterialId = GetMaterialElementId(shapeEditScope); if (materialLayers.Count == 1) { IFCMaterial oneMaterial = materialLayers[0].Material; if (oneMaterial == null) { return(null); } materialId = oneMaterial.GetMaterialElementId(); if (materialId != ElementId.InvalidElementId) { // We will not override the material of the element if the layer material has no color. if (Importer.TheCache.MaterialsWithNoColor.Contains(materialId)) { materialId = ElementId.InvalidElementId; } } return(null); } // Anything below here is something we should report to the user, with the exception of the total thickness // not matching the extrusion thickness. This would require more analysis to determine that it is actually // an error condition. shouldWarn = true; IList <IFCMaterialLayer> realMaterialLayers = new List <IFCMaterialLayer>(); double totalThickness = 0.0; foreach (IFCMaterialLayer materialLayer in materialLayers) { double depth = materialLayer.LayerThickness; if (MathUtil.IsAlmostZero(depth)) { continue; } if (depth < 0.0) { return(null); } realMaterialLayers.Add(materialLayer); totalThickness += depth; } // Axis3 means that the material layers are stacked in the Z direction. This is common for floor slabs. bool isAxis3 = (materialLayerSetUsage.Direction == IFCLayerSetDirection.Axis3); // For elements extruded in the Z direction, if the extrusion layers don't have the same thickness as the extrusion, // this could be one of two reasons: // 1. There is a discrepancy between the extrusion depth and the material layer set usage calculated depth. // 2. There are multiple extrusions in the body definition. // In either case, we will use the extrusion geometry over the calculated material layer set usage geometry. // In the future, we may decide to allow for case #1 by passing in a flag to allow for this. if (isAxis3 && !MathUtil.IsAlmostEqual(totalThickness, currDepth)) { shouldWarn = false; return(null); } int numLayers = realMaterialLayers.Count(); if (numLayers == 0) { return(null); } // We'll use this initial value for the Axis2 case, so read it here. double baseOffsetForLayer = materialLayerSetUsage.Offset; // Needed for Axis2 case only. The axisCurve is the curve defined in the product representation representing // a base curve (an axis) for the footprint of the element. Curve axisCurve = null; // The oriented cuve list represents the 4 curves of supported Axis2 footprint in the following order: // 1. curve along length of object closest to the first material layer with the orientation of the axis curve // 2. connecting end curve // 3. curve along length of object closest to the last material layer with the orientation opposite of the axis curve // 4. connecting end curve. IList <Curve> orientedCurveList = null; if (!isAxis3) { // Axis2 means that the material layers are stacked inthe Y direction. This is by definition for IfcWallStandardCase, // which has a local coordinate system whose Y direction is orthogonal to the length of the wall. if (materialLayerSetUsage.Direction == IFCLayerSetDirection.Axis2) { axisCurve = GetAxisCurve(creator, extrusionPosition); if (axisCurve == null) { return(null); } orientedCurveList = GetOrientedCurveList(loops, axisCurve, extrusionPosition.BasisZ, baseOffsetForLayer, totalThickness); if (orientedCurveList == null) { return(null); } } else { return(null); // Not handled. } } extrusionSolids = new List <GeometryObject>(); bool positiveOrientation = (materialLayerSetUsage.DirectionSense == IFCDirectionSense.Positive); // Always extrude in the positive direction for Axis2. XYZ materialExtrusionDirection = (positiveOrientation || !isAxis3) ? extrusionDirection : -extrusionDirection; // Axis2 repeated values. // The IFC concept of offset direction is reversed from Revit's. XYZ normalDirectionForAxis2 = positiveOrientation ? -extrusionPosition.BasisZ : extrusionPosition.BasisZ; bool axisIsCyclic = (axisCurve == null) ? false : axisCurve.IsCyclic; double axisCurvePeriod = axisIsCyclic ? axisCurve.Period : 0.0; Transform curveLoopTransform = Transform.Identity; IList <CurveLoop> currLoops = null; double depthSoFar = 0.0; for (int ii = 0; ii < numLayers; ii++) { IFCMaterialLayer materialLayer = materialLayers[ii]; // Ignore 0 thickness layers. No need to warn. double depth = materialLayer.LayerThickness; if (MathUtil.IsAlmostZero(depth)) { continue; } // If the thickness is non-zero but invalid, fail. if (!Application.IsValidThickness(depth)) { return(null); } double extrusionDistance = 0.0; if (isAxis3) { // Offset the curve loops if necessary, using the base extrusionDirection, regardless of the direction sense // of the MaterialLayerSetUsage. double offsetForLayer = positiveOrientation ? baseOffsetForLayer + depthSoFar : baseOffsetForLayer - depthSoFar; if (!MathUtil.IsAlmostZero(offsetForLayer)) { curveLoopTransform.Origin = offsetForLayer * extrusionDirection; currLoops = new List <CurveLoop>(); foreach (CurveLoop loop in loops) { CurveLoop newLoop = CurveLoop.CreateViaTransform(loop, curveLoopTransform); if (newLoop == null) { return(null); } currLoops.Add(newLoop); } } else { currLoops = loops; } extrusionDistance = depth; } else { // startClipCurve, firstEndCapCurve, endClipCurve, secondEndCapCurve. Curve[] outline = new Curve[4]; double[][] endParameters = new double[4][]; double startClip = depthSoFar; double endClip = depthSoFar + depth; outline[0] = orientedCurveList[0].CreateOffset(startClip, normalDirectionForAxis2); outline[1] = orientedCurveList[1].Clone(); outline[2] = orientedCurveList[2].CreateOffset(totalThickness - endClip, normalDirectionForAxis2); outline[3] = orientedCurveList[3].Clone(); for (int jj = 0; jj < 4; jj++) { outline[jj].MakeUnbound(); endParameters[jj] = new double[2]; endParameters[jj][0] = 0.0; endParameters[jj][1] = 0.0; } // Trim/Extend the curves so that they make a closed loop. for (int jj = 0; jj < 4; jj++) { IntersectionResultArray resultArray = null; outline[jj].Intersect(outline[(jj + 1) % 4], out resultArray); if (resultArray == null || resultArray.Size == 0) { return(null); } int numResults = resultArray.Size; if ((numResults > 1 && !axisIsCyclic) || (numResults > 2)) { return(null); } UV intersectionPoint = resultArray.get_Item(0).UVPoint; endParameters[jj][1] = intersectionPoint.U; endParameters[(jj + 1) % 4][0] = intersectionPoint.V; if (numResults == 2) { // If the current result is closer to the end of the curve, keep it. UV newIntersectionPoint = resultArray.get_Item(1).UVPoint; int endParamIndex = (jj % 2); double newParamToCheck = newIntersectionPoint[endParamIndex]; double oldParamToCheck = (endParamIndex == 0) ? endParameters[jj][1] : endParameters[(jj + 1) % 4][0]; double currentEndPoint = (endParamIndex == 0) ? orientedCurveList[jj].GetEndParameter(1) : orientedCurveList[(jj + 1) % 4].GetEndParameter(0); // Put in range of [-Period/2, Period/2]. double newDist = (currentEndPoint - newParamToCheck) % axisCurvePeriod; if (newDist < -axisCurvePeriod / 2.0) { newDist += axisCurvePeriod; } if (newDist > axisCurvePeriod / 2.0) { newDist -= axisCurvePeriod; } double oldDist = (currentEndPoint - oldParamToCheck) % axisCurvePeriod; if (oldDist < -axisCurvePeriod / 2.0) { oldDist += axisCurvePeriod; } if (oldDist > axisCurvePeriod / 2.0) { oldDist -= axisCurvePeriod; } if (Math.Abs(newDist) < Math.Abs(oldDist)) { endParameters[jj][1] = newIntersectionPoint.U; endParameters[(jj + 1) % 4][0] = newIntersectionPoint.V; } } } CurveLoop newCurveLoop = new CurveLoop(); for (int jj = 0; jj < 4; jj++) { if (endParameters[jj][1] < endParameters[jj][0]) { if (!outline[jj].IsCyclic) { return(null); } endParameters[jj][1] += Math.Floor(endParameters[jj][0] / axisCurvePeriod + 1.0) * axisCurvePeriod; } outline[jj].MakeBound(endParameters[jj][0], endParameters[jj][1]); newCurveLoop.Append(outline[jj]); } currLoops = new List <CurveLoop>(); currLoops.Add(newCurveLoop); extrusionDistance = currDepth; } // Determine the material id. IFCMaterial material = materialLayer.Material; ElementId layerMaterialId = (material == null) ? ElementId.InvalidElementId : material.GetMaterialElementId(); // The second option here is really for Referencing. Without a UI (yet) to determine whether to show the base // extusion or the layers for objects with material layer sets, we've chosen to display the base material if the layer material // has no color information. This means that the layer is assigned the "wrong" material, but looks better on screen. // We will reexamine this decision (1) for the Open case, (2) if there is UI to toggle between layers and base extrusion, or // (3) based on user feedback. if (layerMaterialId == ElementId.InvalidElementId || Importer.TheCache.MaterialsWithNoColor.Contains(layerMaterialId)) { layerMaterialId = baseMaterialId; } SolidOptions solidOptions = new SolidOptions(layerMaterialId, shapeEditScope.GraphicsStyleId); // Create the extrusion for the material layer. GeometryObject extrusionSolid = GeometryCreationUtilities.CreateExtrusionGeometry( currLoops, materialExtrusionDirection, extrusionDistance, solidOptions); if (extrusionSolid == null) { return(null); } extrusionSolids.Add(extrusionSolid); depthSoFar += depth; } } catch { // Ignore the specific exception, but let the user know there was a problem processing the IfcMaterialLayerSetUsage. shouldWarn = true; return(null); } return(extrusionSolids); }
/// <summary> /// Processes an IfcMaterialLayerSet entity. /// </summary> /// <param name="ifcMaterialLayerSet">The IfcMaterialLayerSet handle.</param> /// <returns>The IFCMaterialLayerSet object.</returns> public static IFCMaterialLayerSet ProcessIFCMaterialLayerSet(IFCAnyHandle ifcMaterialLayerSet) { if (IFCAnyHandleUtil.IsNullOrHasNoValue(ifcMaterialLayerSet)) { Importer.TheLog.LogNullError(IFCEntityType.IfcMaterialLayerSet); return null; } IFCEntity materialLayerSet; if (!IFCImportFile.TheFile.EntityMap.TryGetValue(ifcMaterialLayerSet.StepId, out materialLayerSet)) materialLayerSet = new IFCMaterialLayerSet(ifcMaterialLayerSet); return (materialLayerSet as IFCMaterialLayerSet); }