changeset 262:ed1fadb22c61

added option "sdk" to GenerateOrthancSDK.py
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 12 Aug 2025 08:57:38 +0200
parents 4724fbdf46e9
children 57a625025651
files CodeAnalysis/FunctionBody.mustache CodeAnalysis/GenerateOrthancSDK.py Sources/Autogenerated/orthanc.pyi Sources/Autogenerated/sdk_GlobalFunctions.impl.h Sources/Autogenerated/sdk_OrthancPluginDicomInstance.methods.h Sources/Autogenerated/sdk_OrthancPluginImage.methods.h
diffstat 6 files changed, 74 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/CodeAnalysis/FunctionBody.mustache	Tue Aug 12 08:18:56 2025 +0200
+++ b/CodeAnalysis/FunctionBody.mustache	Tue Aug 12 08:57:38 2025 +0200
@@ -99,7 +99,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {
--- a/CodeAnalysis/GenerateOrthancSDK.py	Tue Aug 12 08:18:56 2025 +0200
+++ b/CodeAnalysis/GenerateOrthancSDK.py	Tue Aug 12 08:57:38 2025 +0200
@@ -41,30 +41,7 @@
 with open(os.path.join(os.path.dirname(__file__), '..', 'OrthancSDKVersion.cmake'), 'r') as f:
     m = re.match('^set\(ORTHANC_SDK_VERSION "([^"]+)"\)$', f.read(), re.MULTILINE)
     assert(m != None)
-    PLUGIN_SDK_VERSION = m.group(1)
-
-    s = PLUGIN_SDK_VERSION.split('.')
-    assert(len(s) == 3)
-    PLUGIN_SDK_VERSION_PARSED = [ int(s[0]), int(s[1]), int(s[2]) ]
-
-
-def IsPrimitiveAvailable(item):
-    since_sdk = item.get('since_sdk')
-    if since_sdk != None:
-        assert(len(since_sdk) == 3)
-        assert(len(PLUGIN_SDK_VERSION_PARSED) == 3)
-        if since_sdk[0] < PLUGIN_SDK_VERSION_PARSED[0]:
-            return True
-        elif since_sdk[0] > PLUGIN_SDK_VERSION_PARSED[0]:
-            return False
-        elif since_sdk[1] < PLUGIN_SDK_VERSION_PARSED[1]:
-            return True
-        elif since_sdk[1] > PLUGIN_SDK_VERSION_PARSED[1]:
-            return False
-        else:
-            return since_sdk[2] <= PLUGIN_SDK_VERSION_PARSED[2]
-    else:
-        return True
+    CMAKE_ORTHANC_SDK_VERSION = m.group(1)
 
 
 ##
@@ -72,22 +49,72 @@
 ##
 
 parser = argparse.ArgumentParser(description = 'Generate Python code to wrap the Orthanc SDK.')
+parser.add_argument('--sdk',
+                    default = os.path.join(ROOT, '../Resources/Orthanc/Sdk-%s/orthanc/OrthancCPlugin.h' % CMAKE_ORTHANC_SDK_VERSION),
+                    help = 'Path to the Orthanc SDK')
 parser.add_argument('--model',
-                    default = os.path.join(os.path.dirname(__file__),
-                                           '../Resources/Orthanc/Sdk-%s/CodeModel.json' % PLUGIN_SDK_VERSION),
-                    help = 'Input code model, as generated by the orthanc-java project')
+                    default = os.path.join(ROOT, '../Resources/Orthanc/Sdk-%s/orthanc/OrthancPluginCodeModel.json' % CMAKE_ORTHANC_SDK_VERSION),
+                    help = 'Input code model, as generated by the orthanc project')
 parser.add_argument('--classes',
-                    default = os.path.join(os.path.dirname(__file__),
-                                           '../Resources/Orthanc/Sdk-%s/ClassDocumentation.json' % PLUGIN_SDK_VERSION),
+                    default = os.path.join(ROOT, '../Resources/Orthanc/Sdk-%s/ClassDocumentation.json' % CMAKE_ORTHANC_SDK_VERSION),
                     help = 'Input description of classes, as defined in the orthanc-java project')
 parser.add_argument('--target',
-                    default = os.path.join(os.path.dirname(__file__),
-                                           '../Sources/Autogenerated'),
+                    default = os.path.join(ROOT, '../Sources/Autogenerated'),
                     help = 'Target folder')
 
 args = parser.parse_args()
 
 
+##
+## Detect the actual version of the Orthanc SDK
+##
+
+with open(args.sdk, 'r') as f:
+    content = f.read()
+
+    major = re.findall(r'#\s*define\s+ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER\s+([0-9.]+)$', content, re.MULTILINE)
+    minor = re.findall(r'#\s*define\s+ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER\s+([0-9.]+)$', content, re.MULTILINE)
+    revision = re.findall(r'#\s*define\s+ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER\s+([0-9.]+)$', content, re.MULTILINE)
+    assert(len(major) == 1)
+    assert(len(minor) == 1)
+    assert(len(revision) == 1)
+
+    SDK_VERSION = [ int(major[0]), int(minor[0]), int(revision[0]) ]
+
+
+def IsPrimitiveAvailable(item, key_prefix = ''):
+    since_sdk = item.get('since_sdk')
+    if since_sdk != None:
+        assert(len(since_sdk) == 3)
+        assert(len(SDK_VERSION) == 3)
+        if since_sdk[0] < SDK_VERSION[0]:
+            available = True
+        elif since_sdk[0] > SDK_VERSION[0]:
+            available = False
+        elif since_sdk[1] < SDK_VERSION[1]:
+            available = True
+        elif since_sdk[1] > SDK_VERSION[1]:
+            available = False
+        else:
+            available = since_sdk[2] <= SDK_VERSION[2]
+
+        if not available:
+            name = item.get('name')
+            if name == None:
+                name = item.get('c_function')
+            if name == None:
+                name = item.get('short_name')
+            if name == None:
+                # For enumerations
+                key = item.get('key')
+                if key != None:
+                    name = '%s_%s' % (key_prefix, key)
+            print('Primitive unavailable in SDK: %s (only available since %s)' % (name, '.'.join(map(str, since_sdk))))
+
+        return available
+    else:
+        return True
+
 
 ##
 ## Configuration of the custom primitives that are manually
@@ -397,7 +424,7 @@
 
     values = []
     for value in e['values']:
-        if IsPrimitiveAvailable(value):
+        if IsPrimitiveAvailable(value, key_prefix = e['name']):
             values.append({
                 'key' : ToUpperCase(value['key']),
                 'value' : value['value'],
--- a/Sources/Autogenerated/orthanc.pyi	Tue Aug 12 08:18:56 2025 +0200
+++ b/Sources/Autogenerated/orthanc.pyi	Tue Aug 12 08:57:38 2025 +0200
@@ -31,7 +31,7 @@
 
 class ChangeType():
     """
-    The supported types of changes that can be signaled to the change callback. Note: this enum is not used to store changes in the DB !
+    The supported types of changes that can be signaled to the change callback. Note: This enumeration is not used to store changes in the database!
     """
 
     """
@@ -3230,6 +3230,7 @@
     def StorageAreaCreate(self, uuid: str, content: bytes, size: int, type: ContentType) -> None:
         """
         This function creates a new file inside the storage area that is currently used by Orthanc.
+        Warning: This function will result in a "not implemented" error on versions of the Orthanc core above 1.12.6.
 
         Args:
           uuid (str): The identifier of the file to be created.
@@ -3243,6 +3244,7 @@
     def StorageAreaRead(self, uuid: str, type: ContentType) -> bytes:
         """
         This function reads the content of a given file from the storage area that is currently used by Orthanc.
+        Warning: This function will result in a "not implemented" error on versions of the Orthanc core above 1.12.6.
 
         Args:
           uuid (str): The identifier of the file to be read.
@@ -3257,6 +3259,7 @@
     def StorageAreaRemove(self, uuid: str, type: ContentType) -> None:
         """
         This function removes a given file from the storage area that is currently used by Orthanc.
+        Warning: This function will result in a "not implemented" error on versions of the Orthanc core above 1.12.6.
 
         Args:
           uuid (str): The identifier of the file to be removed.
--- a/Sources/Autogenerated/sdk_GlobalFunctions.impl.h	Tue Aug 12 08:18:56 2025 +0200
+++ b/Sources/Autogenerated/sdk_GlobalFunctions.impl.h	Tue Aug 12 08:57:38 2025 +0200
@@ -370,7 +370,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {
@@ -403,7 +403,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {
@@ -438,7 +438,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {
@@ -472,7 +472,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {
@@ -982,7 +982,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {
@@ -1178,7 +1178,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {
@@ -2009,7 +2009,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {
@@ -2043,7 +2043,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {
--- a/Sources/Autogenerated/sdk_OrthancPluginDicomInstance.methods.h	Tue Aug 12 08:18:56 2025 +0200
+++ b/Sources/Autogenerated/sdk_OrthancPluginDicomInstance.methods.h	Tue Aug 12 08:57:38 2025 +0200
@@ -366,7 +366,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {
--- a/Sources/Autogenerated/sdk_OrthancPluginImage.methods.h	Tue Aug 12 08:18:56 2025 +0200
+++ b/Sources/Autogenerated/sdk_OrthancPluginImage.methods.h	Tue Aug 12 08:57:38 2025 +0200
@@ -145,7 +145,7 @@
   if (obj == NULL)
   {
     PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
-    return NULL;  
+    return NULL;
   }
   else
   {