changeset 1713:aec45e0b2528

configuration option "DicomWebRoot"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 30 Nov 2020 17:09:46 +0100
parents fb57536fcc5f
children a878e807cd96
files Applications/StoneWebViewer/Plugin/Plugin.cpp Applications/StoneWebViewer/WebApplication/app.js Applications/StoneWebViewer/WebApplication/configuration.json Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp
diffstat 4 files changed, 45 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/Plugin/Plugin.cpp	Mon Nov 30 16:49:04 2020 +0100
+++ b/Applications/StoneWebViewer/Plugin/Plugin.cpp	Mon Nov 30 17:09:46 2020 +0100
@@ -27,6 +27,10 @@
 #include <SystemToolbox.h>
 #include <Toolbox.h>
 
+
+static const std::string STONE_WEB_VIEWER_ROOT = "/stone-webviewer";
+
+
 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
                                         OrthancPluginResourceType resourceType,
                                         const char* resourceId)
@@ -173,6 +177,8 @@
   else
   {
     static const char* CONFIG_SECTION = "StoneWebViewer";
+    static const char* ORTHANC_API_ROOT = "OrthancApiRoot";
+    static const char* DICOM_WEB_ROOT = "DicomWebRoot";
 
     Json::Value config = Json::objectValue;
     
@@ -202,8 +208,16 @@
       }
     }
 
-    config[CONFIG_SECTION]["OrthancApiRoot"] = "..";
+    assert(config[CONFIG_SECTION].type() == Json::objectValue);
+
+    // Assume that the Stone Web viewer is mapped at "/stone-webviewer" in the REST API
+    config[CONFIG_SECTION][ORTHANC_API_ROOT] = "..";
 
+    if (!config[CONFIG_SECTION].isMember(DICOM_WEB_ROOT))
+    {
+      config[CONFIG_SECTION][DICOM_WEB_ROOT] = "../dicom-web";
+    }
+    
     const std::string s = config.toStyledString();
     OrthancPluginAnswerBuffer(context, output, s.c_str(), s.size(), "application/json");
   }
@@ -243,39 +257,39 @@
       OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str());
       
       OrthancPlugins::RegisterRestCallback<ServeConfiguration>
-        ("/stone-webviewer/configuration.json", true);
+        (STONE_WEB_VIEWER_ROOT + "/configuration.json", true);
       
       OrthancPlugins::RegisterRestCallback
         <ServeEmbeddedFile<Orthanc::EmbeddedResources::STONE_WEB_VIEWER_WASM> >
-        ("/stone-webviewer/StoneWebViewer.wasm", true);
+        (STONE_WEB_VIEWER_ROOT + "/StoneWebViewer.wasm", true);
       
       OrthancPlugins::RegisterRestCallback
         <ServeEmbeddedFile<Orthanc::EmbeddedResources::STONE_WEB_VIEWER_JS> >
-        ("/stone-webviewer/StoneWebViewer.js", true);
+        (STONE_WEB_VIEWER_ROOT + "/StoneWebViewer.js", true);
       
       OrthancPlugins::RegisterRestCallback
         <ServeEmbeddedFile<Orthanc::EmbeddedResources::STONE_WRAPPER> >
-        ("/stone-webviewer/stone.js", true);
+        (STONE_WEB_VIEWER_ROOT + "/stone.js", true);
       
       OrthancPlugins::RegisterRestCallback
         <ServeEmbeddedFolder<Orthanc::EmbeddedResources::IMAGES> >
-        ("/stone-webviewer/img/(.*)", true);
+        (STONE_WEB_VIEWER_ROOT + "/img/(.*)", true);
       
       OrthancPlugins::RegisterRestCallback
         <ServeEmbeddedFolder<Orthanc::EmbeddedResources::LIBRARIES_CSS> >
-        ("/stone-webviewer/css/(.*)", true);
+        (STONE_WEB_VIEWER_ROOT + "/css/(.*)", true);
       
       OrthancPlugins::RegisterRestCallback
         <ServeEmbeddedFolder<Orthanc::EmbeddedResources::LIBRARIES_JS> >
-        ("/stone-webviewer/js/(.*)", true);
+        (STONE_WEB_VIEWER_ROOT + "/js/(.*)", true);
       
       OrthancPlugins::RegisterRestCallback
         <ServeEmbeddedFolder<Orthanc::EmbeddedResources::LIBRARIES_WEBFONTS> >
-        ("/stone-webviewer/webfonts/(.*)", true);
+        (STONE_WEB_VIEWER_ROOT + "/webfonts/(.*)", true);
 
       OrthancPlugins::RegisterRestCallback
         <ServeEmbeddedFolder<Orthanc::EmbeddedResources::WEB_APPLICATION> >
-        ("/stone-webviewer/(.*)", true);
+        (STONE_WEB_VIEWER_ROOT + "/(.*)", true);
 
       OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
     }
--- a/Applications/StoneWebViewer/WebApplication/app.js	Mon Nov 30 16:49:04 2020 +0100
+++ b/Applications/StoneWebViewer/WebApplication/app.js	Mon Nov 30 17:09:46 2020 +0100
@@ -1020,7 +1020,8 @@
 
 window.addEventListener('StoneInitialized', function() {
   stone.Setup(Module);
-  stone.SetOrthancRoot('..', true);
+  stone.SetDicomWebRoot(app.globalConfiguration.DicomWebRoot,
+                        true /* assume "/rendered" is available in DICOMweb (could be a configuration option) */);
   stone.SetSoftwareRendering(localStorage.settingSoftwareRendering == '1');
   console.warn('Stone properly initialized');
 
--- a/Applications/StoneWebViewer/WebApplication/configuration.json	Mon Nov 30 16:49:04 2020 +0100
+++ b/Applications/StoneWebViewer/WebApplication/configuration.json	Mon Nov 30 17:09:46 2020 +0100
@@ -65,12 +65,19 @@
     "ExpectedMessageOrigin" : "http://localhost:8042",
 
     /**
+     * Root path of the DICOMweb server. This option is automatically
+     * set by the Orthanc plugin if missing.
+     **/
+    "DicomWebRoot" : "../dicom-web",
+    
+    /**
      * The following parameter can be set if running the Stone Web
-     * viewer from Orthanc, but without using the associated plugin.
-     * Using the plugin would overwrite this setting. This will enable
-     * features that are only available if the Orthanc REST API is
-     * accessible (download of studies, and playing videos). This
-     * option is typically used by the developers of Stone.
+     * viewer from Orthanc, but without using the associated plugin
+     * (e.g. using the "Serve Folders" sample plugin). Using the
+     * plugin would overwrite this setting. This will enable features
+     * that are only available if the Orthanc REST API is accessible
+     * (download of studies, and playing videos). This option is
+     * typically used by the developers of Stone.
      **/
     "OrthancApiRoot" : ".."
   }
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Mon Nov 30 16:49:04 2020 +0100
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Mon Nov 30 17:09:46 2020 +0100
@@ -2894,13 +2894,12 @@
 
 
   EMSCRIPTEN_KEEPALIVE
-  void SetOrthancRoot(const char* uri,
-                      int useRendered)
+  void SetDicomWebRoot(const char* uri,
+                       int useRendered)
   {
     try
     {
-      context_->SetLocalOrthanc(uri);  // For "source_.SetDicomWebThroughOrthancSource()"
-      source_.SetDicomWebSource(std::string(uri) + "/dicom-web");
+      source_.SetDicomWebSource(uri);
       source_.SetDicomWebRendered(useRendered != 0);
     }
     EXTERN_CATCH_EXCEPTIONS;
@@ -2908,11 +2907,13 @@
   
 
   EMSCRIPTEN_KEEPALIVE
-  void SetDicomWebServer(const char* serverName,
-                         int hasRendered)
+  void SetDicomWebThroughOrthanc(const char* orthancRoot,
+                                 const char* serverName,
+                                 int hasRendered)
   {
     try
     {
+      context_->SetLocalOrthanc(orthancRoot);
       source_.SetDicomWebThroughOrthancSource(serverName);
       source_.SetDicomWebRendered(hasRendered != 0);
     }