目录
IFC的空间层级
下面例子:如何从文件中检索空间结构,IFC的空间结构是指代表项目,地点,建筑物,楼层和空间的层次结构。那么查看IFC文件,我们将会发现建筑物可以包含楼层和其他建筑物,楼层可以包含空间以及其他楼层等。而且这种关系是用IfcRelAggregates建模的,但是如果想找到包含在特点空间结构中元素,它就被建模为IfcRelContainedInSpatialStructure,所以取决于想要找到的东西。下面的例子展示了如何使用上面提到的两个关系来搜索和遍历数据以获得完整的层次结构。
using System;
using System.Linq;
using Xbim.Ifc;
using Xbim.Ifc4.Interfaces; namespace BasicExamples
{
class SpatialStructureExample
{
public static void Show()
{
const string file = "SampleHouse.ifc"; using (var model = IfcStore.Open(file))
{
var project = model.Instances.FirstOrDefault<IIfcProject>();
PrintHierarchy(project, );
}
} private static void PrintHierarchy(IIfcObjectDefinition o, int level)
{
Console.WriteLine(string.Format("{0}{1} [{2}]", GetIndent(level), o.Name, o.GetType().Name)); //只有空间元素可以包含建筑元素
var spatialElement = o as IIfcSpatialStructureElement;
if (spatialElement != null)
{
//使用 IfcRelContainedInSpatialElement 获取包含的元素
var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
foreach (var element in containedElements)
Console.WriteLine(string.Format("{0} ->{1} [{2}]", GetIndent(level), element.Name, element.GetType().Name));
}
//利用 IfcRelAggregares 获取空间结构元素的空间分解
foreach (var item in o.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
PrintHierarchy(item, level +);
} private static string GetIndent(int level)
{
var indent = "";
for (int i = ; i < level; i++)
indent += " ";
return indent;
}
}
}
输出样本模型
Project Number [IfcProject]
Default [IfcSite]
[IfcBuilding]
Ground Floor [IfcBuildingStorey]
->Basic Wall:Wall-Ext_102Bwk-75Ins-100LBlk-12P: [IfcWall]
->Basic Wall:Wall-Ext_102Bwk-75Ins-100LBlk-12P: [IfcWall]
->Basic Wall:Wall-Ext_102Bwk-75Ins-100LBlk-12P: [IfcWall]
->Curtain Wall:Curtain_Wall-Exterior_Glazing: [IfcCurtainWall]
->Curtain Wall:Curtain_Wall-Exterior_Glazing: [IfcCurtainWall]
->Basic Wall:Wall-Partn_12P-70MStd-12P: [IfcWallStandardCase]
->Basic Wall:Wall-Partn_12P-70MStd-12P: [IfcWallStandardCase]
->Doors_ExtDbl_Flush:1810x2110mm: [IfcDoor]
->Doors_IntSgl:810x2110mm: [IfcDoor]
->Doors_IntSgl:810x2110mm: [IfcDoor]
->Windows_Sgl_Plain:1810x1210mm: [IfcWindow]
->Windows_Sgl_Plain:1810x1210mm: [IfcWindow]
->Windows_Sgl_Plain:1810x1210mm: [IfcWindow]
->Compound Ceiling:Plain: [IfcCovering]
->Compound Ceiling:Plain: [IfcCovering]
->Compound Ceiling:Plain: [IfcCovering]
->Floor:Floor-Grnd-Susp_65Scr-80Ins-100Blk-75PC: [IfcSlab]
->Windows_Sgl_Plain:1810x1210mm: [IfcWindow]
- Living room [IfcSpace]
->Furniture_Table_Dining_w-Chairs_Rectangular:2000x1000x750mm_w-6_Seats: [IfcFurniture]
->Chair - Dining:Chair - Dining: [IfcFurniture]
->Chair - Dining:Chair - Dining: [IfcFurniture]
->Chair - Dining:Chair - Dining: [IfcFurniture]
->Chair - Dining:Chair - Dining: [IfcFurniture]
->Chair - Dining:Chair - Dining: [IfcFurniture]
->Chair - Dining:Chair - Dining: [IfcFurniture]
->Furniture_Couch_Viper:2290x950x340mm: [IfcFurniture]
->Furniture_Chair_Viper:1120x940x350mm: [IfcFurniture]
->Furniture_Chair_Viper:1120x940x350mm: [IfcFurniture]
->Furniture_Table_Coffee_1:1200x550x450mm: [IfcFurniture]
->Furniture_Piano:1370x600x1170mm: [IfcFurniture]
- Bedroom [IfcSpace]
->Furniture_Desk:1525x762mm: [IfcFurniture]
->Furniture_Bed_1:1525x2007x355mm-Queen: [IfcFurniture]
- Entrance hall [IfcSpace]
Roof [IfcBuildingStorey]
->Basic Roof:Roof_Flat-4Felt-150Ins-50Scr-150Conc-12Plr: [IfcRoof]
->Floor:Simple floor: [IfcSlab]
- Roof [IfcSpace]