{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# 04. Dictionaries and Semantic Data\n\nGive a room a name and an occupancy, then read those values back.\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-04-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-04-01"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Attach meaning to geometry\n\nA dictionary stores named values. Keep the object returned by `SetDictionary`.\n",
   "id": "tutorial-04-02"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "from topologicpy.Cell import Cell\nfrom topologicpy.Dictionary import Dictionary\nfrom topologicpy.Topology import Topology\n\nroom = Cell.Prism(width=4, length=3, height=3)\nproperties = Dictionary.ByKeysValues([\"name\", \"occupancy\"], [\"Studio\", 4])\nroom = Topology.SetDictionary(room, properties)\nstored = Topology.Dictionary(room)\nprint(\"Name:\", Dictionary.ValueAtKey(stored, \"name\"))\nprint(\"Occupancy:\", Dictionary.ValueAtKey(stored, \"occupancy\"))\nassert Dictionary.ValueAtKey(stored, \"occupancy\") == 4\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-04-03"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Preserve attributes during a transformation\n\nDictionary behaviour depends on the operation. Request transfer explicitly here and verify the result instead of assuming every operation preserves metadata.\n",
   "id": "tutorial-04-04"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "moved_room = Topology.Translate(room, x=5, transferDictionaries=True)\nmoved_properties = Topology.Dictionary(moved_room)\nprint(\"Moved room:\", Dictionary.ValueAtKey(moved_properties, \"name\"))\nassert Dictionary.ValueAtKey(moved_properties, \"name\") == \"Studio\"\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-04-05"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Try it yourself\n\nAdd a `department` property and read it from the translated room.\n",
   "id": "tutorial-04-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
}
