diff --git a/src/RvtIO/Ifc/IfcExporter.QuantitiesCurrent.cs b/src/RvtIO/Ifc/IfcExporter.QuantitiesCurrent.cs index 736de5c5..3ad15a99 100644 --- a/src/RvtIO/Ifc/IfcExporter.QuantitiesCurrent.cs +++ b/src/RvtIO/Ifc/IfcExporter.QuantitiesCurrent.cs @@ -1229,8 +1229,10 @@ private List DoorWindowQuantitiesCurrent(QuantityContextCurrent c { var result = new List(); Element? type = TypeOfCurrent(element, context.Elements); + // A wall standing as a panel of a curtain wall is exported as one, but to its own doors and windows it is still a wall. bool inCurtainWall = element.SerializedHostId is { } hostId - && context.Products.TryGetValue(hostId, out var host) && host.ifcType == "IFCCURTAINWALL"; + && context.Products.TryGetValue(hostId, out var host) && host.ifcType == "IFCCURTAINWALL" + && !(context.Elements.TryGetValue(hostId, out var hostElement) && IsCurtainPanelWall(hostElement, host.ifcType)); double? height = ExactNamedParameterFeetCurrent(element, type, "Height", true, -1001300, -1010300) * FeetToMetres ?? (inCurtainWall ? InstanceFrameExtentMetresCurrent(element, 2) : null); // Without a parameter of its own (a panel of a curtain wall holds only a bounding-box estimate) the width is the extent of diff --git a/src/RvtIO/Ifc/IfcExporter.cs b/src/RvtIO/Ifc/IfcExporter.cs index f0b0a496..b045090f 100644 --- a/src/RvtIO/Ifc/IfcExporter.cs +++ b/src/RvtIO/Ifc/IfcExporter.cs @@ -939,7 +939,8 @@ int ResolveStorey(Element element, double[]? outline = null) .Where(candidate => candidate.CategoryId == -2000011 && visibleWallIds.Contains(candidate.Id) && !(curtainWallIds.Contains(candidate.Id) - && candidate.Layers is not { Count: > 0 }) + && candidate.Layers is not { Count: > 0 } + || curtainPanelWallIds.Contains(candidate.Id)) && ShouldSuppressPhantomStoreyWallProduct( "IFCWALLSTANDARDCASE", IntParam(candidate, -1001952), storeyIds) // A project Level that is not a building story is a real level, not a phantom. @@ -1886,8 +1887,6 @@ bool HasCompetingExactHostedWriterAuthority( if (elem.CategoryId == -2000011 && !visibleWallIds.Contains(elem.Id)) { Skip(elem, "wall-not-visible"); continue; } - if (curtainPanelWallIds.Contains(elem.Id)) - { Skip(elem, "curtain-panel-wall"); continue; } if (elem.CategoryId is -2000171 or -2000170) { @@ -1911,8 +1910,9 @@ bool HasCompetingExactHostedWriterAuthority( ? "IFCOPENINGELEMENT" // A serialized CompoundStructure is the defining body of a basic/stacked system // wall. - : elem.CategoryId == -2000011 && curtainWallIds.Contains(elem.Id) + : elem.CategoryId == -2000011 && (curtainWallIds.Contains(elem.Id) && elem.Layers is not { Count: > 0 } + || curtainPanelWallIds.Contains(elem.Id)) ? "IFCCURTAINWALL" : elem.CategoryId == -2000011 && ShouldExportAsIfcWall(elem, CurrentProfile) ? "IFCWALL" @@ -6050,6 +6050,7 @@ int EnsureUnnamedMaterial() => bool agrees = (type.SerializedSystemTypeClassId, element.CategoryId, ifcType) switch { (512, -2000011, "IFCWALL" or "IFCWALLSTANDARDCASE") => true, + (512, -2000011, "IFCCURTAINWALL") when element.SerializedCurtainHostId is > 0 => true, (1915, -2000032, "IFCSLAB") => true, (1915, -2001300, "IFCSLAB" or "IFCROOF") => true, (646, -2000038, "IFCCOVERING") => true, @@ -6165,7 +6166,8 @@ int EnsureUnnamedMaterial() => var associated = CurrentProfile ? group.Where(item => item.Product.ifcType != "IFCWALL").ToList() : group.ToList(); if (associated.Count == 0) continue; - bool wallLayers = first.Product.ifcType is "IFCWALL" or "IFCWALLSTANDARDCASE"; + bool wallLayers = first.Product.ifcType is "IFCWALL" or "IFCWALLSTANDARDCASE" + || IsCurtainPanelWall(first.Element, first.Product.ifcType); bool directLayerSet = first.Native != null && (CurrentProfile ? first.Element.CategoryId == -2000035 : first.Element.CategoryId == -2001300); @@ -7040,6 +7042,9 @@ static string ParameterType(double parameter) => return true; } + private static bool IsCurtainPanelWall(Element element, string ifcType) => + ifcType == "IFCCURTAINWALL" && element.CategoryId == -2000011 && element.SerializedCurtainHostId is > 0; + /// /// The layer-set cache keys native HostObjAttr sets by the own type, not by identical /// material/thickness contents. @@ -7048,7 +7053,9 @@ internal static string MaterialLayerSetGroupKey( Element element, string ifcType, IReadOnlyDictionary elements, IReadOnlyDictionary counts) { - string direction = ifcType is "IFCWALL" or "IFCWALLSTANDARDCASE" ? "AXIS2" : "AXIS3"; + // A curtain panel wall has its own groups: the first member of a group names and orients the layers of all of them. + string direction = IsCurtainPanelWall(element, ifcType) ? "AXIS2|curtain-panel" + : ifcType is "IFCWALL" or "IFCWALLSTANDARDCASE" ? "AXIS2" : "AXIS3"; string layers = string.Join(';', (element.Layers ?? []) .OrderBy(layer => layer.LayerIndex) .Select(layer => $"{layer.MaterialId}:{layer.ThicknessMm.ToString("R", CultureInfo.InvariantCulture)}")); @@ -7082,6 +7089,7 @@ internal static string MaterialLayerSetGroupKey( bool agrees = (type.SerializedSystemTypeClassId, element.CategoryId, ifcType) switch { (512, -2000011, "IFCWALL" or "IFCWALLSTANDARDCASE") => true, + (512, -2000011, "IFCCURTAINWALL") when element.SerializedCurtainHostId is > 0 => true, (1915, -2000032 or -2001300, "IFCSLAB") => true, (646, -2000038, "IFCCOVERING") => true, _ => false, @@ -67427,6 +67435,8 @@ private static Dictionary WriteTypeObjectsAndRelDefinesByTypeCoreFo var typeGroupOrder = new List<(int typeId, int symbolId, string typeClass, int ownerId, int systemTypeId)>(); var predefinedTypes = new Dictionary<(int typeId, int symbolId, string typeClass, int ownerId, int systemTypeId), string>(); var exactSystemTypeGroups = new HashSet<(int typeId, int symbolId, string typeClass, int ownerId, int systemTypeId)>(); + // Groups with a member that is not a wall standing as a panel of a curtain wall. + var nonPanelGroups = new HashSet<(int typeId, int symbolId, string typeClass, int ownerId, int systemTypeId)>(); var firstMemberElementId = new Dictionary<(int typeId, int symbolId, string typeClass, int ownerId, int systemTypeId), int>(); var connectedSystemTypes = currentProfile ? ResolveConnectedSystemTypes(elemById) : null; var stairShapes = currentProfile ? ReadProductAttributes(w, exportedProducts, @@ -67583,14 +67593,16 @@ private static Dictionary WriteTypeObjectsAndRelDefinesByTypeCoreFo if (!exactSystemType) exactSystemTypeGroups.Remove(key); } members.Add(product.entityId); + if (!IsCurtainPanelWall(instElem, product.ifcType)) + nonPanelGroups.Add(key); firstInstanceIfcType.TryAdd(key, product.ifcType); firstMemberElementId[key] = firstMemberElementId.TryGetValue(key, out int earlier) ? Math.Min(earlier, elementId) : elementId; } // A native type may govern both walls and curtain walls. - var classCounts = typeGroupOrder.GroupBy(key => (key.typeId, key.symbolId, key.ownerId, key.systemTypeId)) - .ToDictionary(group => group.Key, group => group.Select(key => key.typeClass).Distinct().Count()); + var identities = typeGroupOrder.GroupBy(key => (key.typeId, key.symbolId, key.ownerId, key.systemTypeId)) + .ToDictionary(group => group.Key, group => (Classes: group.Count(), NonPanelClasses: group.Count(nonPanelGroups.Contains))); var guidClaimant = typeGroupOrder.Where(key => key.symbolId > 0) .GroupBy(key => (key.symbolId, key.ownerId)) .ToDictionary(group => group.Key, group => group.MinBy(key => firstMemberElementId[key])); @@ -67621,7 +67633,11 @@ private static Dictionary WriteTypeObjectsAndRelDefinesByTypeCoreFo : $"{typeElemId.ToString(CultureInfo.InvariantCulture)}:symbol:{originalSymbolId.ToString(CultureInfo.InvariantCulture)}"; if (ownerId > 0) identityKey += $":instance:{ownerId.ToString(CultureInfo.InvariantCulture)}"; if (systemTypeId > 0) identityKey += $":system:{systemTypeId.ToString(CultureInfo.InvariantCulture)}"; - if (classCounts[(typeElemId, originalSymbolId, ownerId, systemTypeId)] > 1) + // The IfcCurtainWallType made for wall panels is an extra object beside the type of the other walls: it takes + // neither the identity nor the native GlobalId from them. + var (classes, nonPanelClasses) = identities[(typeElemId, originalSymbolId, ownerId, systemTypeId)]; + bool extraPanelType = !nonPanelGroups.Contains(key) && classes > 1; + if (extraPanelType || nonPanelClasses > 1) identityKey += $":{typeClass}"; string guidArg = S(IfcGuid.FromName($"type:{identityKey}")); int firstElementId = firstMemberElementId[key]; @@ -67662,7 +67678,7 @@ private static Dictionary WriteTypeObjectsAndRelDefinesByTypeCoreFo // The GlobalId rule uses the original symbol's own ExportId for mapped types, except // overrides/collisions. - bool typeElementGuid = exactSystemTypeGroups.Contains(key) + bool typeElementGuid = exactSystemTypeGroups.Contains(key) && !extraPanelType || typeClass is "IFCPIPESEGMENTTYPE" or "IFCCABLECARRIERSEGMENTTYPE" || currentProfile && (typeClass is "IFCDUCTSEGMENTTYPE" or "IFCSTAIRFLIGHTTYPE" or "IFCTYPEPRODUCT" or "IFCRAILINGTYPE" || typeClass == "IFCSLABTYPE" && typeElem.CategoryId == StairsLandingsCategoryId); diff --git a/tests/RvtIO.Tests/IfcExporterTypeObjectsTests.cs b/tests/RvtIO.Tests/IfcExporterTypeObjectsTests.cs index 453c330f..768cb7c8 100644 --- a/tests/RvtIO.Tests/IfcExporterTypeObjectsTests.cs +++ b/tests/RvtIO.Tests/IfcExporterTypeObjectsTests.cs @@ -1484,28 +1484,156 @@ string Export(bool withOutline) } [Theory] - [InlineData(IfcProfile.Legacy, 1)] - [InlineData(IfcProfile.Current, 0)] - public void BasicWallBoundToACurtainWallAsAPanel_IsNotExportedByCurrent(IfcProfile version, int wallPanels) + [InlineData(IfcProfile.Legacy, "IFCWALL", 1)] + [InlineData(IfcProfile.Current, "IFCCURTAINWALL", 0)] + public void BasicWallBoundToACurtainWallAsAPanel_ExportsAndAggregatesUnderCurtainWall( + IfcProfile version, string childIfcType, int wallCount) { - // In the current profile a wall whose owner is a curtain wall is not exported: only plates, members, doors and windows are - // aggregated under a curtain wall. + // Reference exports write basic-wall curtain panels as IfcCurtainWall aggregated under their + // parent IfcCurtainWall (Legacy emits them as IfcWall). var type = TypeElement(500, "Curtain type", "Curtain family"); type.CategoryId = WallCategoryId; type.SerializedCurtainWallFunction = 1; var parent = Product(100, WallCategoryId, "OST_Walls", 500, null); parent.TypeId = 500; parent.Geometry = null; parent.BoundingBox = null; var panel = Product(101, -2000170, "OST_CurtainWallPanels", null, null); panel.SerializedCurtainHostId = 100; - var wallPanel = Product(102, WallCategoryId, "OST_Walls", null, null); + var wallType = TypeElement(501, "Panel wall", "Basic Wall"); + wallType.CategoryId = WallCategoryId; wallType.SerializedBasicWallTypeFunction = 1; + wallType.SerializedBasicWallTypeName = "Panel wall"; + var wallPanel = Product(102, WallCategoryId, "OST_Walls", 501, null); wallPanel.SerializedCurtainHostId = 100; - string ifc = ExportToText(version, type, parent, panel, wallPanel); - int parentId = SoleEntityId(ifc, "IFCCURTAINWALL"); + string ifc = ExportToText(version, type, wallType, parent, panel, wallPanel); + int parentId = SoleEntityIdForTag(ifc, "IFCCURTAINWALL", "100"); int plateId = SoleEntityId(ifc, "IFCPLATE"); + int wallChildId = SoleEntityIdForTag(ifc, childIfcType, "102"); var rel = Assert.Single(EntityIds(ifc, "IFCRELAGGREGATES") .Select(id => EntityArgs(ifc, id, "IFCRELAGGREGATES")), args => args[4] == $"#{parentId}"); - Assert.Equal(wallPanels == 0 ? $"(#{plateId})" : $"(#{plateId},#{SoleEntityIdForTag(ifc, "IFCWALL", "102")})", rel[5]); - Assert.Equal(wallPanels, EntityIds(ifc, "IFCWALL").Count + EntityIds(ifc, "IFCWALLSTANDARDCASE").Count); + var expectedChildren = new[] { plateId, wallChildId }.OrderBy(id => id).Select(id => $"#{id}"); + Assert.Equal($"({string.Join(",", expectedChildren)})", rel[5]); + Assert.Equal(wallCount, EntityIds(ifc, "IFCWALL").Count + EntityIds(ifc, "IFCWALLSTANDARDCASE").Count); + if (version == IfcProfile.Current) + { + Assert.Contains(EntityIds(ifc, "IFCCURTAINWALLTYPE"), id => EntityArgs(ifc, id, "IFCCURTAINWALLTYPE")[7] == "'501'"); + } + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void WallTypeSharedWithACurtainPanelWall_KeepsItsOwnGlobalId(bool withRegularWall) + { + var exportId = Guid.Parse("11111111-2222-3333-4444-555555555555"); + var curtainType = TypeElement(500, "Curtain type", "Curtain family"); + curtainType.CategoryId = WallCategoryId; curtainType.SerializedCurtainWallFunction = 1; + var parent = Product(100, WallCategoryId, "OST_Walls", 500, null); + parent.TypeId = 500; parent.Geometry = null; parent.BoundingBox = null; + var panel = Product(101, -2000170, "OST_CurtainWallPanels", null, null); + panel.SerializedCurtainHostId = 100; + var wallType = TypeElement(501, "Shared wall", "Basic Wall"); + wallType.CategoryId = WallCategoryId; wallType.SerializedBasicWallTypeFunction = 1; + wallType.SerializedBasicWallTypeName = "Shared wall"; + wallType.SerializedSystemTypeClassId = 512; wallType.SerializedExportId = exportId; + var wallPanel = Product(102, WallCategoryId, "OST_Walls", 501, null, centreX: 10); + wallPanel.SerializedCurtainHostId = 100; + wallPanel.TypeId = 501; wallPanel.SerializedSystemTypeId = 501; + var regularWall = Product(103, WallCategoryId, "OST_Walls", 501, null, centreX: 20); + regularWall.TypeId = 501; regularWall.SerializedSystemTypeId = 501; + Element[] elements = [curtainType, wallType, parent, panel, wallPanel]; + + string ifc = ExportToText(IfcProfile.Current, withRegularWall ? [.. elements, regularWall] : elements); + + string expected = $"'{RvtIO.Ifc.IfcGuid.ToIfcGuid(exportId)}'"; + var panelType = Assert.Single(EntityIds(ifc, "IFCCURTAINWALLTYPE") + .Select(id => EntityArgs(ifc, id, "IFCCURTAINWALLTYPE")), args => args[7] == "'501'"); + if (!withRegularWall) + { + Assert.Equal(expected, panelType[0]); + return; + } + var basicType = Assert.Single(EntityIds(ifc, "IFCWALLTYPE") + .Select(id => EntityArgs(ifc, id, "IFCWALLTYPE")), args => args[7] == "'501'"); + Assert.Equal(expected, basicType[0]); + Assert.NotEqual(expected, panelType[0]); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void CurtainPanelWall_KeepsItsLayerGroupApartFromHostsWithTheSameLayers(bool panelFirst) + { + var curtainType = TypeElement(500, "Curtain type", "Curtain family"); + curtainType.CategoryId = WallCategoryId; curtainType.SerializedCurtainWallFunction = 1; + var parent = Product(100, WallCategoryId, "OST_Walls", 500, null); + parent.TypeId = 500; parent.Geometry = null; parent.BoundingBox = null; + var panel = Product(101, -2000170, "OST_CurtainWallPanels", null, null); + panel.SerializedCurtainHostId = 100; + var wallPanel = Product(102, WallCategoryId, "OST_Walls", null, null, centreX: 10); + wallPanel.SerializedCurtainHostId = 100; + var floor = Product(103, -2000032, "OST_Floors", null, null, centreX: 20); + static List Layers() => + [new MaterialLayer { LayerIndex = 0, MaterialId = 700, MaterialName = "Concrete", ThicknessMm = 200 }]; + wallPanel.Layers = Layers(); floor.Layers = Layers(); + Element[] hosts = panelFirst ? [wallPanel, floor] : [floor, wallPanel]; + + string ifc = ExportToText(IfcProfile.Current, [curtainType, parent, panel, .. hosts]); + + Assert.Equal(".AXIS2.", LayerUsageDirection(ifc, SoleEntityIdForTag(ifc, "IFCCURTAINWALL", "102"))); + Assert.Equal(".AXIS3.", LayerUsageDirection(ifc, SoleEntityIdForTag(ifc, "IFCSLAB", "103"))); + // Nor may a panel join the walls: the first member of a group names and orients it. + var none = new Dictionary(); + var counts = new Dictionary(); + Assert.NotEqual(IfcExporter.MaterialLayerSetGroupKey(wallPanel, "IFCWALL", none, counts), + IfcExporter.MaterialLayerSetGroupKey(wallPanel, "IFCCURTAINWALL", none, counts)); + } + + [Theory] + // In a curtain wall itself the area is height times width: 7 ft x 3 ft. + [InlineData(100, 21.0)] + // A wall standing as a panel is still a wall to its door: half of the 40 ft2 surface of the door. + [InlineData(102, 20.0)] + public void DoorArea_FollowsWhetherTheHostIsACurtainWallOrAPanelWall(int hostId, double squareFeet) + { + var curtainType = TypeElement(500, "Curtain type", "Curtain family"); + curtainType.CategoryId = WallCategoryId; curtainType.SerializedCurtainWallFunction = 1; + var parent = Product(100, WallCategoryId, "OST_Walls", 500, null); + parent.TypeId = 500; parent.Geometry = null; parent.BoundingBox = null; + var panel = Product(101, -2000170, "OST_CurtainWallPanels", null, null); + panel.SerializedCurtainHostId = 100; + var wallPanel = Product(102, WallCategoryId, "OST_Walls", null, null, centreX: 10); + wallPanel.SerializedCurtainHostId = 100; + var door = Product(104, -2000023, "OST_Doors", null, null, centreX: 20); + door.SerializedHostId = hostId; + door.CoarseSurfaceArea = 40; + foreach (var (id, feet) in new[] { (-1001300, 7.0), (-1001301, 3.0) }) + door.Parameters.Add(new Parameter + { + Id = id, StorageType = StorageType.Double, Value = feet, + Definition = new Definition { Id = id, Name = id == -1001300 ? "Height" : "Width" }, + }); + + string ifc = ExportToText(IfcProfile.Current, curtainType, parent, panel, wallPanel, door); + + int doorId = SoleEntityId(ifc, "IFCDOOR"); + var definitions = EntityIds(ifc, "IFCRELDEFINESBYPROPERTIES") + .Select(id => EntityArgs(ifc, id, "IFCRELDEFINESBYPROPERTIES")) + .Where(args => args[4].Trim('(', ')').Split(',').Contains($"#{doorId}")) + .Select(args => int.Parse(args[5].TrimStart('#'))); + int quantitySet = Assert.Single(definitions.Intersect(EntityIds(ifc, "IFCELEMENTQUANTITY"))); + var members = EntityArgs(ifc, quantitySet, "IFCELEMENTQUANTITY")[5].Trim('(', ')').Split(',') + .Select(reference => int.Parse(reference.TrimStart('#'))); + int areaId = Assert.Single(members.Intersect(EntityIds(ifc, "IFCQUANTITYAREA"))); + double area = double.Parse(EntityArgs(ifc, areaId, "IFCQUANTITYAREA")[3], + System.Globalization.CultureInfo.InvariantCulture); + Assert.Equal(squareFeet * 0.09290304, area, 6); + } + + private static string LayerUsageDirection(string ifc, int productId) + { + var rel = Assert.Single(EntityIds(ifc, "IFCRELASSOCIATESMATERIAL") + .Select(id => EntityArgs(ifc, id, "IFCRELASSOCIATESMATERIAL")), + args => args[4].Trim('(', ')').Split(',').Contains($"#{productId}")); + return EntityArgs(ifc, int.Parse(rel[5].TrimStart('#')), "IFCMATERIALLAYERSETUSAGE")[1]; } /// A 4 x 3 x 0.5 box roof: bottom and top as horizontal faces with a world-aligned plane frame.