changeset 1552:a4d82f1bcb10

user preferences: not for diagnostic use, software rendering
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Aug 2020 15:35:01 +0200
parents c54bc5bffd01
children bf02a90ca9ca
files Applications/StoneWebViewer/WebApplication/app.js Applications/StoneWebViewer/WebApplication/index.html Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp
diffstat 3 files changed, 125 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebApplication/app.js	Thu Aug 13 22:05:13 2020 +0200
+++ b/Applications/StoneWebViewer/WebApplication/app.js	Fri Aug 14 15:35:01 2020 +0200
@@ -103,11 +103,18 @@
       ready: false,
       leftMode: 'grid',   // Can be 'small', 'grid' or 'full'
       leftVisible: true,
-      showWarning: false,
       viewportLayoutButtonsVisible: false,
       activeViewport: 0,
       showInfo: true,
       showReferenceLines: true,
+
+      modalWarning: false,
+      modalNotDiagnostic: false,
+      modalPreferences: false,
+
+      // User preferences (stored in the local storage)
+      settingNotDiagnostic: true,
+      settingSoftwareRendering: false,
       
       viewport1Width: '100%',
       viewport1Height: '100%',
@@ -177,6 +184,12 @@
     },
     showReferenceLines: function(newVal, oldVal) {
       stone.ShowReferenceLines(newVal ? 1 : 0);
+    },
+    settingNotDiagnostic: function(newVal, oldVal) {
+      localStorage.settingNotDiagnostic = (newVal ? '1' : '0');
+    },
+    settingSoftwareRendering: function(newVal, oldVal) {
+      localStorage.settingSoftwareRendering = (newVal ? '1' : '0');
     }
   },
   methods: {
@@ -451,11 +464,29 @@
       if (canvas != '') {
         stone.InvertContrast(canvas);
       }
+    },
+
+    ApplyPreferences() {
+      this.modalPreferences = false;
+
+      if ((stone.IsSoftwareRendering() != 0) != this.settingSoftwareRendering) {
+        document.location.reload();
+      }
     }
   },
   
   mounted: function() {
     this.SetViewportLayout('1x1');
+
+    if (localStorage.settingNotDiagnostic) {
+      this.settingNotDiagnostic = (localStorage.settingNotDiagnostic == '1');
+    }
+    
+    if (localStorage.settingSoftwareRendering) {
+      this.settingSoftwareRendering = (localStorage.settingSoftwareRendering == '1');
+    }
+    
+    this.modalNotDiagnostic = this.settingNotDiagnostic;
   }
 });
 
@@ -464,6 +495,7 @@
 window.addEventListener('StoneInitialized', function() {
   stone.Setup(Module);
   stone.SetOrthancRoot('..', true);
+  stone.SetSoftwareRendering(localStorage.settingSoftwareRendering == '1');
   console.warn('Native Stone properly intialized');
 
   var study = getParameterFromUrl('study');
@@ -565,7 +597,7 @@
   // Enable support for tooltips in Bootstrap
   //$('[data-toggle="tooltip"]').tooltip();
 
-  //app.showWarning = true;
+  //app.modalWarning = true;
 
 
   $('#windowing-popover').popover({
--- a/Applications/StoneWebViewer/WebApplication/index.html	Thu Aug 13 22:05:13 2020 +0200
+++ b/Applications/StoneWebViewer/WebApplication/index.html	Fri Aug 14 15:35:01 2020 +0200
@@ -41,7 +41,7 @@
 
       <div class="fluid-height fluid-width" v-show="ready">
 
-        <div class="wvWarning wvPrintExclude" v-show="showWarning">
+        <div class="wvWarning wvPrintExclude" v-show="modalWarning">
           <div class="wvWarning-content clearfix">
             <span class="wvWarning-text">
               <h2 class="mb10"><i class="fa fa-exclamation-triangle wvWarning-icon mr5"></i>Warning!</h2>
@@ -53,7 +53,55 @@
             </span> 
           </div>
           <div class="text-right mb10 mr10">
-            <button class="btn btn-primary" @click="showWarning=false">OK</button>
+            <button class="btn btn-primary" @click="modalWarning=false">OK</button>
+          </div>
+        </div>
+
+
+        <div class="wvWarning wvPrintExclude" v-show="modalNotDiagnostic">
+          <div class="wvWarning-content clearfix">
+            <span class="wvWarning-text">
+              <h2 class="mb10"><i class="fa fa-exclamation-triangle wvWarning-icon mr5"></i>Warning!</h2>
+              <p class="mn mb10" style="color:#000">
+                This viewer is not suitable for diagnostic usage.
+              </p>
+
+              <div class="form-check">
+                <input class="form-check-input" type="checkbox" v-model="settingNotDiagnostic" id="checkboxNotDiagnostic1">
+                <label class="form-check-label" for="checkboxNotDiagnostic1" style="color:#000;display:inline">
+                  Show this warning at startup
+                </label>
+              </div>
+            </span> 
+          </div>
+          <div class="text-right mb10 mr10">
+            <button class="btn btn-primary" @click="modalNotDiagnostic=false">OK</button>
+          </div>
+        </div>
+
+
+        <div class="wvWarning wvPrintExclude" v-show="modalPreferences">
+          <div class="wvWarning-content clearfix">
+            <span class="wvWarning-text">
+              <h2 class="mb10">Preferences</h2>
+              
+              <div class="form-check">
+                <input class="form-check-input" type="checkbox" v-model="settingNotDiagnostic" id="checkboxNotDiagnostic2">
+                <label class="form-check-label" for="checkboxNotDiagnostic2" style="color:#000;display:inline">
+                  Warn about diagnostic usage at startup
+                </label>
+              </div>
+
+              <div class="form-check">
+                <input class="form-check-input" type="checkbox" v-model="settingSoftwareRendering" id="checkboxSoftwareRendering">
+                <label class="form-check-label" for="checkboxSoftwareRendering" style="color:#000;display:inline">
+                  Use software rendering (will reload the viewer)
+                </label>
+              </div>
+            </span> 
+          </div>
+          <div class="text-right mb10 mr10">
+            <button class="btn btn-primary" @click="ApplyPreferences()">OK</button>
           </div>
         </div>
 
@@ -106,7 +154,7 @@
                 <i class="fa fa-th"></i>
               </div>
 
-              <p class="clear disclaimer mbn">For patients, teachers and researchers.</p>
+              <!--p class="clear disclaimer mbn">For patients, teachers and researchers.</p-->
             </div>        
             <div class="wvLayoutLeft__contentMiddle">
 
@@ -279,6 +327,13 @@
                 <i class="fa fa-bars"></i>
               </button>
             </div>
+
+            <div class="ng-scope inline-object">
+              <button class="wvButton--underline text-center"
+                      v-on:click="modalPreferences = true">
+                <i class="fa fa-user"></i>
+              </button>
+            </div>
           </div>
 
           
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Thu Aug 13 22:05:13 2020 +0200
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Fri Aug 14 15:35:01 2020 +0200
@@ -1522,11 +1522,10 @@
   ViewerViewport(OrthancStone::ILoadersContext& context,
                  const OrthancStone::DicomSource& source,
                  const std::string& canvas,
-                 boost::shared_ptr<FramesCache> cache) :
+                 boost::shared_ptr<FramesCache> cache,
+                 bool softwareRendering) :
     context_(context),
     source_(source),
-    viewport_(OrthancStone::WebGLViewport::Create(canvas)),
-    //viewport_(OrthancStone::WebAssemblyCairoViewport::Create(canvas)),
     cache_(cache),
     fitNextContent_(true),
     isCtrlDown_(false)
@@ -1535,6 +1534,17 @@
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
     }
+
+    if (softwareRendering)
+    {
+      LOG(INFO) << "Creating Cairo viewport in canvas: " << canvas;
+      viewport_ = OrthancStone::WebAssemblyCairoViewport::Create(canvas);
+    }
+    else
+    {
+      LOG(INFO) << "Creating WebGL viewport in canvas: " << canvas;
+      viewport_ = OrthancStone::WebGLViewport::Create(canvas);
+    }
     
     emscripten_set_wheel_callback(viewport_->GetCanvasCssSelector().c_str(), this, true, OnWheel);
     emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey);
@@ -1598,10 +1608,11 @@
   static boost::shared_ptr<ViewerViewport> Create(OrthancStone::ILoadersContext::ILock& lock,
                                                   const OrthancStone::DicomSource& source,
                                                   const std::string& canvas,
-                                                  boost::shared_ptr<FramesCache> cache)
+                                                  boost::shared_ptr<FramesCache> cache,
+                                                  bool softwareRendering)
   {
     boost::shared_ptr<ViewerViewport> viewport(
-      new ViewerViewport(lock.GetContext(), source, canvas, cache));
+      new ViewerViewport(lock.GetContext(), source, canvas, cache, softwareRendering));
 
     viewport->loader_ = OrthancStone::DicomResourcesLoader::Create(lock);
     viewport->Register<OrthancStone::DicomResourcesLoader::SuccessMessage>(
@@ -1910,6 +1921,7 @@
 static boost::shared_ptr<FramesCache> cache_;
 static boost::shared_ptr<OrthancStone::WebAssemblyLoadersContext> context_;
 static std::string stringBuffer_;
+static bool softwareRendering_ = false;
 
 
 
@@ -1954,7 +1966,8 @@
   if (found == allViewports_.end())
   {
     std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(context_->Lock());
-    boost::shared_ptr<ViewerViewport> viewport(ViewerViewport::Create(*lock, source_, canvas, cache_));
+    boost::shared_ptr<ViewerViewport> viewport(
+      ViewerViewport::Create(*lock, source_, canvas, cache_, softwareRendering_));
     viewport->AcquireObserver(new WebAssemblyObserver);
     allViewports_[canvas] = viewport;
     return viewport;
@@ -2269,4 +2282,18 @@
     }
     EXTERN_CATCH_EXCEPTIONS;
   }  
+
+
+  EMSCRIPTEN_KEEPALIVE
+  void SetSoftwareRendering(int softwareRendering)
+  {
+    softwareRendering_ = softwareRendering;
+  }  
+
+
+  EMSCRIPTEN_KEEPALIVE
+  int IsSoftwareRendering()
+  {
+    return softwareRendering_;
+  }  
 }