diff --git a/documentation/content/pages/python-tutorial/AdvancedTopics.rst b/documentation/content/pages/python-tutorial/AdvancedTopics.rst index c47baeb2..1913e350 100644 --- a/documentation/content/pages/python-tutorial/AdvancedTopics.rst +++ b/documentation/content/pages/python-tutorial/AdvancedTopics.rst @@ -32,3 +32,83 @@ go through all the components of a trans-hierarchical net. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For a starter, how to get all the leaf cells... + + +9.5 Dynamically decorating data-base objects +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When writing algorithms directly in Python, it may come in handy to be +able to add attributes over the Hurricane data-base objects. As C++ +objects exposed to the Python realm cannot natively do so (it would +means to be able to modify a C++ aobject attributes *at runtime*), +we add a special Property tasked with handling the extra Python +attributes. The syntax has been made as simple as possible. + +.. code-block:: python + + from Hurricane import PythonAttributes + + class MyAttribute ( object ): + count = 0 + + def __init__ ( self ): + self.value = MyAttribute.count + print( '{} has been created'.format(self) ) + MyAttribute.count += 1 + + def __del__ ( self ): + print( '{} has been deleted'.format(self) ) + + def __str__ ( self ): + return ''.format(self.value) + + + def demoAttributes ( cell ): + PythonAttributes.enable( cell ) + cell.myAttribute0 = MyAttribute() + cell.myAttribute1 = MyAttribute() + print( 'cell.myAttribute0 =', cell.myAttribute0 ) + del cell.myAttribute0 + PythonAttributes.disable( cell ) + + +Detailing the life cycle of Python attributes on a DBo_: + +1. Enabling the addition of Python attribute on a DBo_: + + .. code-block:: python + + PythonAttributes.enable( cell ) + +2. Adding/removing properties on the DBo_: + + .. code-block:: python + + cell.myAttribute0 = MyAttribute() + cell.myAttribute1 = MyAttribute() + print( 'cell.myAttribute0 =', cell.myAttribute0 ) + del cell.myAttribute0 + +3. And finally disabling the use of Python attributes on the DBo. + Any still attached Python attributes will be released. + + .. code-block:: python + + PythonAttributes.disable( cell ) + + .. note:: + + When the attributes of a DBo_ are released it does not automatically + imply that they are removed. Their reference count is decreased, and + if they are only referenced here, they will be deleted. But if other + variables still holds reference onto them, they will stay allocateds. + +4. There is no need to keep track of all the DBo_ that have Python + attributes to disable them. One can directly call: + + .. code-block:: python + + PythonAttributes.disableAll() + + + diff --git a/documentation/content/pages/python-tutorial/definitions.rst b/documentation/content/pages/python-tutorial/definitions.rst index d21ad1b3..2e503641 100644 --- a/documentation/content/pages/python-tutorial/definitions.rst +++ b/documentation/content/pages/python-tutorial/definitions.rst @@ -12,6 +12,7 @@ .. _Point: ../../hurricane/classHurricane_1_1Point.html .. _Points: ../../hurricane/classHurricane_1_1Point.html .. _Box: ../../hurricane/classHurricane_1_1Box.html +.. _DBo: ../../hurricane/classHurricane_1_1DBo.html .. _Cell: ../../hurricane/classHurricane_1_1Cell.html .. _Net: ../../hurricane/classHurricane_1_1Net.html .. _Nets: ../../hurricane/classHurricane_1_1Net.html @@ -34,6 +35,7 @@ .. _Transformation: ../../hurricane/classHurricane_1_1Transformation.html .. _Orientation: ../../hurricane/classHurricane_1_1Orientation.html .. _Occurrence: ../../hurricane/classHurricane_1_1Occurrence.html +.. _PythonAttributes: ../../hurricane/classIsobar_1_1PythonAttributes.html .. Hurricane Viewer doxygen doc links. .. _CellViewer: ../../viewer/classHurricane_1_1CellViewer.html diff --git a/documentation/content/pdfs/CheckToolkit.pdf b/documentation/content/pdfs/CheckToolkit.pdf index c22f7aea..08e021a0 100644 Binary files a/documentation/content/pdfs/CheckToolkit.pdf and b/documentation/content/pdfs/CheckToolkit.pdf differ diff --git a/documentation/content/pdfs/PythonCpp.pdf b/documentation/content/pdfs/PythonCpp.pdf index 17574286..663355dc 100644 Binary files a/documentation/content/pdfs/PythonCpp.pdf and b/documentation/content/pdfs/PythonCpp.pdf differ diff --git a/documentation/content/pdfs/PythonTutorial.pdf b/documentation/content/pdfs/PythonTutorial.pdf index 2e95c1ec..d22baab2 100644 Binary files a/documentation/content/pdfs/PythonTutorial.pdf and b/documentation/content/pdfs/PythonTutorial.pdf differ diff --git a/documentation/content/pdfs/RDS.pdf b/documentation/content/pdfs/RDS.pdf index 0d57b99e..2302c57e 100644 Binary files a/documentation/content/pdfs/RDS.pdf and b/documentation/content/pdfs/RDS.pdf differ diff --git a/documentation/content/pdfs/Stratus.pdf b/documentation/content/pdfs/Stratus.pdf index ed921f91..445bf103 100644 Binary files a/documentation/content/pdfs/Stratus.pdf and b/documentation/content/pdfs/Stratus.pdf differ diff --git a/documentation/content/pdfs/UsersGuide.pdf b/documentation/content/pdfs/UsersGuide.pdf index 735c5fd1..e4fba96e 100644 Binary files a/documentation/content/pdfs/UsersGuide.pdf and b/documentation/content/pdfs/UsersGuide.pdf differ diff --git a/documentation/output/index.html b/documentation/output/index.html index e211632b..e1a1817d 100644 --- a/documentation/output/index.html +++ b/documentation/output/index.html @@ -123,7 +123,7 @@
-

Contents

+

Contents