{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# 12. IFC and BIM\n\nRead a supplied miniature IFC building with one room. Inspect its semantic model and extract its space geometry.\n\n**Goal:** Complete one small workflow. Run the cells from top to bottom in a fresh kernel.\n\n**Extra dependencies:** None beyond the base environment.\n\nAll examples use metres unless stated otherwise.\n",
   "id": "tutorial-12-00"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "import os\nos.environ[\"TOPOLOGICPY_CORE_BACKEND\"] = \"pythonocc\"\n\nimport topologicpy\nfrom topologicpy.Core import Core\n\nassert topologicpy.__version__ == \"0.9.86\", \"Use TopologicPy 0.9.86 for these tutorials.\"\nassert type(Core.Backend()).__name__ == \"PythonOCCBackend\", \"Restart with the pythonocc backend.\"\nprint(\"TopologicPy\", topologicpy.__version__, \"—\", type(Core.Backend()).__name__)\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-12-01"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Read the IFC model\n\nThe supplied file was generated for this tutorial. It contains a project, site, building, storey and a single 4 × 3 × 3 m space, so no large external model is required.\n",
   "id": "tutorial-12-02"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "from pathlib import Path\nfrom topologicpy.IFC import IFC\n\npath = Path(\"data\") / \"one_room.ifc\"\nmodel = IFC.ModelByPath(str(path))\nsummary = IFC.Summary(model)\nprint(summary)\nassert model is not None\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-12-03"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Extract the space geometry\n\nIFC distinguishes semantic objects from their geometric representations. Filter the import to spaces, then verify the resulting volume.\n",
   "id": "tutorial-12-04"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "from topologicpy.Topology import Topology\nfrom topologicpy.Cell import Cell\n\nspaces = IFC.TopologiesByPath(str(path), includeTypes=[\"IfcSpace\"], topologyType=\"cell\")\nprint(\"Spaces:\", len(spaces))\nroom = spaces[0]\nprint(\"Type:\", Topology.TypeAsString(room))\nprint(\"Volume:\", Cell.Volume(room))\nassert len(spaces) == 1\nassert abs(Cell.Volume(room) - 36) < 0.001\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-12-05"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Try it yourself\n\nInspect `Topology.Dictionary(room)` to see which IFC properties were attached. This uses TopologicPy’s built-in IFC importer; no IfcOpenShell installation is required.\n",
   "id": "tutorial-12-06"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (TopologicPy tutorials)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
