From 38e130715e883fda5964a7d3ad120fc552908cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petrus=20Hyv=C3=B6nen?= <petrus.hyvonen@gmail.com> Date: Fri, 13 Nov 2020 08:55:14 +0100 Subject: [PATCH] Updated documentation on python subclassing and __init__ --- examples/The_Basics.ipynb | 60 ++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/examples/The_Basics.ipynb b/examples/The_Basics.ipynb index 91e7256..0c98d3b 100644 --- a/examples/The_Basics.ipynb +++ b/examples/The_Basics.ipynb @@ -144,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -204,7 +204,7 @@ "output_type": "stream", "text": [ "Java version: 1.8.0_152-release\n", - "Orekit version: 10.0\n" + "Orekit version: 10.2\n" ] } ], @@ -243,7 +243,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -252,7 +252,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -351,7 +351,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -360,7 +360,7 @@ "<Vector3D: {138,869,605,874.96655; -47,461,924,824.28846; -20,575,480,674.707344}>" ] }, - "execution_count": 20, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -430,6 +430,52 @@ "Example:" ] }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "from org.orekit.propagation.sampling import PythonOrekitFixedStepHandler" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "class StepHandler(PythonOrekitFixedStepHandler):\n", + " \n", + " def __init__(self, my_value):\n", + " self.my_value = my_value\n", + " super(StepHandler, self).__init__()\n", + "\n", + " def init(self, s0, t, step):\n", + " pass\n", + "\n", + " def handleStep(self, state, isLast):\n", + " # your code goes here that is executed for every step\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the example above, note:\n", + "\n", + " - The class is subclassing a special class, instead of OrekitFixedStepHandler, PythonOrekitFixedStepHandler is used.\n", + " - All methods in the class / interface needs to be implemented for java to accept it. If not used, just use a pass statement.\n", + " - If a custom __init__ is used, the super needs also to be called to finalize the initialization of the object" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -586,7 +632,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "metadata": {}, "outputs": [ { -- GitLab