changeset 2:2bdb9acb7dcf

added STL viewer button at instance level too
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Jul 2023 09:41:31 +0200
parents 0f03a8a0bd6f
children 0fb06c6a6c87
files Sources/OrthancExplorer.js Sources/Plugin.cpp
diffstat 2 files changed, 81 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/Sources/OrthancExplorer.js	Mon Jul 17 18:54:31 2023 +0200
+++ b/Sources/OrthancExplorer.js	Tue Jul 18 09:41:31 2023 +0200
@@ -22,39 +22,66 @@
  **/
 
 
+const SOP_CLASS_UID_STL = '1.2.840.10008.5.1.4.1.1.104.3';
+
+function AddOpenStlViewerButton(instanceId, id, parent) {
+  var b = $('<a>')
+      .attr('id', id)
+      .attr('data-role', 'button')
+      .attr('href', '#')
+      .attr('data-icon', 'search')
+      .attr('data-theme', 'e')
+      .text('STL viewer')
+      .button();
+
+  b.insertAfter($('#' + parent));
+  b.click(function() {
+    if ($.mobile.pageData) {
+      window.open('../stl/app/viewer.html?instance=' + instanceId);
+    }
+  });
+}
+
+
 $('#series').live('pagebeforeshow', function() {
   var seriesId = $.mobile.pageData.uuid;
 
-  $('#stl-button').remove();
+  $('#stl-button-series').remove();
 
   // Test whether this is a whole-slide image by check the SOP Class
   // UID of one instance of the series
   GetResource('/series/' + seriesId, function(series) {
-    var instanceId = series['Instances'][0];
-    
-    $.ajax({
-      url: '/instances/' + instanceId + '/metadata/SopClassUid',
-      success: function(sopClassUid) {
-        if (sopClassUid == '1.2.840.10008.5.1.4.1.1.104.3') {
+    if (series['Instances'].length == 1) {
+      var instanceId = series['Instances'][0];
 
-          // This is an "Encapsulated STL Storage" IOD, register the button
-          var b = $('<a>')
-              .attr('id', 'stl-button')
-              .attr('data-role', 'button')
-              .attr('href', '#')
-              .attr('data-icon', 'search')
-              .attr('data-theme', 'e')
-              .text('STL viewer')
-              .button();
-
-          b.insertAfter($('#series-info'));
-          b.click(function() {
-            if ($.mobile.pageData) {
-              window.open('../stl/app/viewer.html?instance=' + instanceId);
-            }
-          });
+      $.ajax({
+        url: '/instances/' + instanceId + '/metadata/SopClassUid',
+        success: function(sopClassUid) {
+          if (sopClassUid == SOP_CLASS_UID_STL) {
+            // This is an "Encapsulated STL Storage" IOD, register the button
+            AddOpenStlViewerButton(instanceId, 'stl-button-series', 'series-info');
+          }
         }
-      }
-    });
+      });
+    }
   });
 });
+
+
+$('#instance').live('pagebeforeshow', function() {
+  var instanceId = $.mobile.pageData.uuid;
+
+  $('#stl-button-instance').remove();
+
+  // Test whether this is a whole-slide image by check the SOP Class
+  // UID of one instance of the series
+  $.ajax({
+    url: '/instances/' + instanceId + '/metadata/SopClassUid',
+    success: function(sopClassUid) {
+      if (sopClassUid == SOP_CLASS_UID_STL) {
+        // This is an "Encapsulated STL Storage" IOD, register the button
+        AddOpenStlViewerButton(instanceId, 'stl-button-instance', 'instance-info');
+      }
+    }
+  });
+});
--- a/Sources/Plugin.cpp	Mon Jul 17 18:54:31 2023 +0200
+++ b/Sources/Plugin.cpp	Tue Jul 18 09:41:31 2023 +0200
@@ -1212,9 +1212,24 @@
       else
       {
         std::string description;
+
+        if (parsed.GetTagValue(description, Orthanc::DICOM_TAG_SERIES_DESCRIPTION))
+        {
+          description += ": ";
+        }
+        else
+        {
+          description.clear();
+        }
+
+        bool first = true;
         for (std::set<std::string>::const_iterator it = roiNames.begin(); it != roiNames.end(); ++it)
         {
-          if (!description.empty())
+          if (first)
+          {
+            first = false;
+          }
+          else
           {
             description += ", ";
           }
@@ -1279,12 +1294,6 @@
     OrthancPluginSetDescription(context, "STL plugin for Orthanc.");
 
     OrthancPlugins::RegisterRestCallback<ServeFile>("/stl/app/(.*)", true);
-
-    // Extend the default Orthanc Explorer with custom JavaScript for STL
-    std::string explorer;
-    Orthanc::EmbeddedResources::GetFileResource(explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER);
-    OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str());
-
     OrthancPlugins::RegisterRestCallback<ListStructures>("/stl/rt-struct/([0-9a-f-]+)", true);
 
     if (hasCreateDicomStl_)
@@ -1292,6 +1301,19 @@
       OrthancPlugins::RegisterRestCallback<Encode>("/stl/encode", true);
     }
 
+    // Extend the default Orthanc Explorer with custom JavaScript for STL
+    std::string explorer;
+
+    {
+      Orthanc::EmbeddedResources::GetFileResource(explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER);
+
+      std::map<std::string, std::string> dictionary;
+      dictionary["HAS_CREATE_DICOM_STL"] = (hasCreateDicomStl_ ? "true" : "false");
+      explorer = Orthanc::Toolbox::SubstituteVariables(explorer, dictionary);
+
+      OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str());
+    }
+
     return 0;
   }