changeset 466:5055031f4a06 bgo-commands-codegen

- Added browserify to build. This allows using require calls for modules that work with tsc compiler. - removed older stuff related to Protocol Buffers and Flatbuffers - changed triple-slash references to import statements - module prefixes are now added at call sites - added cmake module for filename handling - switched to Ninja for sample build - Added virtual dtor in ICommand
author bgo-osimis
date Mon, 11 Feb 2019 16:00:04 +0100
parents cc47e6eaefb0
children cef55b4e6c21
files Applications/Commands/ICommand.h Applications/Samples/CMakeLists.txt Applications/Samples/SimpleViewer/ApplicationCommands.fbs Applications/Samples/SimpleViewer/Wasm/simple-viewer.ts Applications/Samples/SimpleViewer/Wasm/tsconfig-simple-viewer.json Applications/Samples/Web/simple-viewer-single-file.ts Applications/Samples/Web/simple-viewer-single-file.tsconfig.json Applications/Samples/Web/single-frame-editor.ts Applications/Samples/Web/single-frame-editor.tsconfig.json Applications/Samples/Web/single-frame.ts Applications/Samples/Web/single-frame.tsconfig.json Applications/Samples/build-wasm-ext.sh Applications/Samples/build-wasm.sh Applications/Samples/build-web.sh Applications/Samples/samples-library.js Applications/StoneApplicationContext.h Platforms/Wasm/WasmDelayedCallExecutor.js Platforms/Wasm/WasmPlatformApplicationAdapter.cpp Platforms/Wasm/WasmWebService.js Platforms/Wasm/default-library.js Platforms/Wasm/stone-framework-loader.ts Platforms/Wasm/wasm-application-runner.ts Platforms/Wasm/wasm-viewport.ts README.md Resources/CMake/FlatBuffersConfiguration.cmake Resources/CMake/ProtobufCodeGeneration.cmake Resources/CMake/Utilities.cmake Resources/CommandTool/flatc-tests/basic/BasicCommands.fbs Resources/CommandTool/flatc-tests/basic/CMakeLists.txt Resources/CommandTool/flatc-tests/basic/basic_test_gen.ps1 Resources/CommandTool/flatc-tests/basic/main.cpp Resources/CommandTool/protoc-tests/basic.proto Resources/CommandTool/protoc-tests/basic_js_test.ps1 Resources/CommandTool/protoc-tests/basic_test.html Resources/CommandTool/protoc-tests/basic_ts_test.ps1 Resources/CommandTool/protoc-tests/package-lock.json
diffstat 36 files changed, 345 insertions(+), 678 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Commands/ICommand.h	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Commands/ICommand.h	Mon Feb 11 16:00:04 2019 +0100
@@ -35,6 +35,8 @@
       : name_(name)
     {}
   public:
+    virtual ~ICommand() 
+    {}
     virtual void Execute() = 0;
 //    virtual void Configure(const Json::Value& arguments) = 0;
     const std::string& GetName() const
--- a/Applications/Samples/CMakeLists.txt	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/CMakeLists.txt	Mon Feb 11 16:00:04 2019 +0100
@@ -31,11 +31,14 @@
   ## Configuration of the Emscripten compiler for WebAssembly target
   #####################################################################
 
-  set(WASM_FLAGS "-s WASM=1")
+  set(WASM_FLAGS "-s WASM=1 -O0 -g0")
+  message("*****************************************************************************")
+  message("WARNING: optimizations are disabled in emcc!!! Enable them for production use")
+  message("*****************************************************************************")
   set(WASM_MODULE_NAME "StoneFrameworkModule" CACHE STRING "Name of the WebAssembly module")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WASM_FLAGS}")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WASM_FLAGS}")
-  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --js-library ${STONE_SOURCES_DIR}/Applications/Samples/samples-library.js --js-library ${STONE_SOURCES_DIR}/Platforms/Wasm/WasmWebService.js --js-library ${STONE_SOURCES_DIR}/Platforms/Wasm/WasmDelayedCallExecutor.js --js-library ${STONE_SOURCES_DIR}/Platforms/Wasm/default-library.js  -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'")
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --js-library ${STONE_SOURCES_DIR}/Platforms/Wasm/WasmWebService.js --js-library ${STONE_SOURCES_DIR}/Platforms/Wasm/WasmDelayedCallExecutor.js --js-library ${STONE_SOURCES_DIR}/Platforms/Wasm/default-library.js  -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'")
 
   # Handling of memory
   #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1")  # Resize
@@ -84,7 +87,6 @@
 LIST(APPEND ORTHANC_BOOST_COMPONENTS program_options)
 
 include(../../Resources/CMake/OrthancStoneConfiguration.cmake)
-include(../../Resources/CMake/FlatBuffersConfiguration.cmake)
 
 add_library(OrthancStone STATIC
   ${ORTHANC_STONE_SOURCES}
@@ -169,7 +171,7 @@
 
 if (ENABLE_QT OR ENABLE_WASM)
 
-      GenerateCodeFromFlatBufferSchema("${ORTHANC_STONE_ROOT}/Applications/Samples/SimpleViewer/ApplicationCommands.fbs")
+      # GenerateCodeFromFlatBufferSchema("${ORTHANC_STONE_ROOT}/Applications/Samples/SimpleViewer/ApplicationCommands.fbs")
 
       list(APPEND SIMPLE_VIEWER_APPLICATION_SOURCES ${FLATC_AUTOGENERATED_SOURCES})
       message(STATUS "SIMPLE_VIEWER_APPLICATION_SOURCES = ${SIMPLE_VIEWER_APPLICATION_SOURCES}")
--- a/Applications/Samples/SimpleViewer/ApplicationCommands.fbs	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-// Example IDL file for our monster's schema.
-namespace Orthanc.Stone.Applications;
-
-union VsolCommands {SelectPanel, ConfigurePanel, StartAcquisition}
-union VsolReplies { SelectPanelReply, StartAcquisitionReply }
-
-table SelectPanel {
-  panelNumber:int32;
-}
-
-table SelectPanelReply {
-  ok:bool;
-  errorMessage:string;
-}
-
-table ConfigurePanel {
-}
-
-table StartAcquisition {
-}
-
-table StartAcquisitionReply {
-  ok:bool;
-}
-
-table VsolCommand {
-  command: VsolCommands;
-}
-
-table VsolReply {
-  command: VsolReplies;
-}
-
-// root_type Monster;
-
--- a/Applications/Samples/SimpleViewer/Wasm/simple-viewer.ts	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/SimpleViewer/Wasm/simple-viewer.ts	Mon Feb 11 16:00:04 2019 +0100
@@ -1,6 +1,6 @@
-///<reference path='../../../../Platforms/Wasm/wasm-application-runner.ts'/>
+import wasmApplicationRunner = require('../../../../Platforms/Wasm/wasm-application-runner');
 
-InitializeWasmApplication("OrthancStoneSimpleViewer", "/orthanc");
+wasmApplicationRunner.InitializeWasmApplication("OrthancStoneSimpleViewer", "/orthanc");
 
 function SelectTool(toolName: string) {
   var command = {
@@ -9,8 +9,7 @@
     args: {
     }                                                                                                                       
   };
-  SendMessageToStoneApplication(JSON.stringify(command));
-
+  wasmApplicationRunner.SendMessageToStoneApplication(JSON.stringify(command));
 }
 
 function PerformAction(actionName: string) {
@@ -20,7 +19,7 @@
     args: {
     }
   };
-  SendMessageToStoneApplication(JSON.stringify(command));
+  wasmApplicationRunner.SendMessageToStoneApplication(JSON.stringify(command));
 }
 
 class SimpleViewerUI {
@@ -31,9 +30,7 @@
   public constructor() {
     // install "SelectTool" handlers
     document.querySelectorAll("[tool-selector]").forEach((e) => {
-      console.log(e);
       (e as HTMLButtonElement).addEventListener("click", () => {
-        console.log(e);
         SelectTool(e.attributes["tool-selector"].value);
       });
     });
--- a/Applications/Samples/SimpleViewer/Wasm/tsconfig-simple-viewer.json	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/SimpleViewer/Wasm/tsconfig-simple-viewer.json	Mon Feb 11 16:00:04 2019 +0100
@@ -1,9 +1,9 @@
 {
     "extends" : "../../Web/tsconfig-samples",
     "compilerOptions": {
-        "outFile": "../../build-web/simple-viewer/app-simple-viewer.js"
     },
     "include" : [
-        "simple-viewer.ts"
+        "simple-viewer.ts",
+        "../../build-wasm/ApplicationCommands_generated.ts"
     ]
-}
\ No newline at end of file
+}
--- a/Applications/Samples/Web/simple-viewer-single-file.ts	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/Web/simple-viewer-single-file.ts	Mon Feb 11 16:00:04 2019 +0100
@@ -1,6 +1,6 @@
-///<reference path='../../../Platforms/Wasm/wasm-application-runner.ts'/>
+import wasmApplicationRunner = require('../../../Platforms/Wasm/wasm-application-runner');
 
-InitializeWasmApplication("OrthancStoneSimpleViewerSingleFile", "/orthanc");
+wasmApplicationRunner.InitializeWasmApplication("OrthancStoneSimpleViewerSingleFile", "/orthanc");
 
 function SelectTool(toolName: string) {
     var command = {
@@ -9,7 +9,7 @@
             toolName: toolName
         }
     };
-    SendMessageToStoneApplication(JSON.stringify(command));
+    wasmApplicationRunner.SendMessageToStoneApplication(JSON.stringify(command));
 
 }
 
@@ -19,7 +19,7 @@
         commandType: "simple",
         args: {}
     };
-    SendMessageToStoneApplication(JSON.stringify(command));
+    wasmApplicationRunner.SendMessageToStoneApplication(JSON.stringify(command));
 }
 
 //initializes the buttons
--- a/Applications/Samples/Web/simple-viewer-single-file.tsconfig.json	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/Web/simple-viewer-single-file.tsconfig.json	Mon Feb 11 16:00:04 2019 +0100
@@ -1,7 +1,7 @@
 {
     "extends" : "./tsconfig-samples",
     "compilerOptions": {
-        "outFile": "../build-web/app-simple-viewer-single-file.js"
+        // "outFile": "../build-web/app-simple-viewer-single-file.js"
     },
     "include" : [
         "simple-viewer-single-file.ts"
--- a/Applications/Samples/Web/single-frame-editor.ts	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/Web/single-frame-editor.ts	Mon Feb 11 16:00:04 2019 +0100
@@ -1,3 +1,3 @@
-///<reference path='../../../Platforms/Wasm/wasm-application-runner.ts'/>
+import wasmApplicationRunner = require('../../../Platforms/Wasm/wasm-application-runner');
 
-InitializeWasmApplication("OrthancStoneSingleFrameEditor", "/orthanc");
+wasmApplicationRunner.InitializeWasmApplication("OrthancStoneSingleFrameEditor", "/orthanc");
--- a/Applications/Samples/Web/single-frame-editor.tsconfig.json	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/Web/single-frame-editor.tsconfig.json	Mon Feb 11 16:00:04 2019 +0100
@@ -1,9 +1,8 @@
 {
     "extends" : "./tsconfig-samples",
     "compilerOptions": {
-        "outFile": "../build-web/app-single-frame-editor.js"
     },
     "include" : [
         "single-frame-editor.ts"
     ]
-}
\ No newline at end of file
+}
--- a/Applications/Samples/Web/single-frame.ts	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/Web/single-frame.ts	Mon Feb 11 16:00:04 2019 +0100
@@ -1,3 +1,4 @@
-///<reference path='../../../Platforms/Wasm/wasm-application-runner.ts'/>
+import wasmApplicationRunner = require('../../../Platforms/Wasm/wasm-application-runner');
 
-InitializeWasmApplication("OrthancStoneSingleFrame", "/orthanc");
+wasmApplicationRunner.InitializeWasmApplication("OrthancStoneSingleFrame", "/orthanc");
+
--- a/Applications/Samples/Web/single-frame.tsconfig.json	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/Web/single-frame.tsconfig.json	Mon Feb 11 16:00:04 2019 +0100
@@ -1,9 +1,8 @@
 {
     "extends" : "./tsconfig-samples",
     "compilerOptions": {
-        "outFile": "../build-web/app-single-frame.js"
     },
     "include" : [
         "single-frame.ts"
     ]
-}
\ No newline at end of file
+}
--- a/Applications/Samples/build-wasm-ext.sh	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-#!/bin/bash
-#
-# usage:
-# to build all targets:
-# ./build-wasm.sh
-#
-# to build a single target:
-# ./build-wasm.sh OrthancStoneSingleFrameEditor
-
-set -e
-
-target=${1:-all}
-
-# we will create the output files in a "build-wasm" folder in current location
-
-# let's save current dir
-currentDir=$(pwd)
-
-scriptDirRel=$(dirname $0)
-#echo $scriptDirRel
-scriptDirAbs=$(realpath $scriptDirRel)
-echo $scriptDirAbs
-
-pushd
-# echo "$0"
-# echo $BASH_SOURCE
-# echo "$BASH_SOURCE"
-# scriptDir=dirname $0
-# echo "***********"
-# echo "***********"
-
-#echo "Script folder is" 
-#echo "$(cd "$(dirname "$BASH_SOURCE")"; pwd)/$(basename ""$BASH_SOURCE")"
-
-#samplesRootDir=$(pwd)
-samplesRootDir=${scriptDirAbs}
-echo "samplesRootDir = " ${samplesRootDir}
-
-mkdir -p build-wasm
-cd build-wasm
-
-source ~/apps/emsdk/emsdk_env.sh
-cmake -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN}/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release -DSTONE_SOURCES_DIR=$samplesRootDir/../.. -DORTHANC_FRAMEWORK_SOURCE=path -DORTHANC_FRAMEWORK_ROOT=$samplesRootDir/../../../orthanc -DALLOW_DOWNLOADS=ON $samplesRootDir -DENABLE_WASM=ON
-make -j 5 $target
-
-echo "-- building the web application -- "
-cd ${samplesRootDir}
-./build-web-ext.sh
-
-popd
--- a/Applications/Samples/build-wasm.sh	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/build-wasm.sh	Mon Feb 11 16:00:04 2019 +0100
@@ -18,8 +18,15 @@
 cd $samplesRootDir/build-wasm
 
 source ~/apps/emsdk/emsdk_env.sh
-cmake -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN}/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release -DSTONE_SOURCES_DIR=$currentDir/../../../orthanc-stone -DORTHANC_FRAMEWORK_SOURCE=path -DORTHANC_FRAMEWORK_ROOT=$currentDir/../../../orthanc -DALLOW_DOWNLOADS=ON .. -DENABLE_WASM=ON
-make -j 5 $target
+cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN}/cmake/Modules/Platform/Emscripten.cmake \
+  -DCMAKE_BUILD_TYPE=Release \
+  -DSTONE_SOURCES_DIR=$currentDir/../../../orthanc-stone \
+  -DORTHANC_FRAMEWORK_SOURCE=path \
+  -DORTHANC_FRAMEWORK_ROOT=$currentDir/../../../orthanc \
+  -DALLOW_DOWNLOADS=ON .. \
+  -DENABLE_WASM=ON
+
+ninja $target
 
 echo "-- building the web application -- "
 cd $currentDir
--- a/Applications/Samples/build-web.sh	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/Samples/build-web.sh	Mon Feb 11 16:00:04 2019 +0100
@@ -8,35 +8,51 @@
 currentDir=$(pwd)
 samplesRootDir=$(pwd)
 
+echo "*************************************************************************"
+echo "samplesRootDir = $samplesRootDir"
+echo "*************************************************************************"
+
 outputDir=$samplesRootDir/build-web/
-mkdir -p $outputDir
+mkdir -p "$outputDir"
 
 # files used by all single files samples
-cp $samplesRootDir/Web/index.html $outputDir
-cp $samplesRootDir/Web/samples-styles.css $outputDir
+cp "$samplesRootDir/Web/index.html" "$outputDir"
+cp "$samplesRootDir/Web/samples-styles.css" "$outputDir"
 
 # build simple-viewer-single-file (obsolete project)
 if [[ $target == "all" || $target == "OrthancStoneSimpleViewerSingleFile" ]]; then
   cp $samplesRootDir/Web/simple-viewer-single-file.html $outputDir
-  tsc --allowJs --project $samplesRootDir/Web/simple-viewer-single-file.tsconfig.json
-  cp $currentDir/build-wasm/OrthancStoneSimpleViewerSingleFile.js  $outputDir
-  cp $currentDir/build-wasm/OrthancStoneSimpleViewerSingleFile.wasm  $outputDir
+  tsc --project $samplesRootDir/Web/simple-viewer-single-file.tsconfig.json --outDir "$outputDir"
+  browserify \
+      "$outputDir/Platforms/Wasm/wasm-application-runner.js" \
+      "$outputDir/Applications/Samples/Web/simple-viewer-single-file.js" \
+      -o "$outputDir/app-simple-viewer-single-file.js"
+  cp "$currentDir/build-wasm/OrthancStoneSimpleViewerSingleFile.js"  $outputDir
+  cp "$currentDir/build-wasm/OrthancStoneSimpleViewerSingleFile.wasm"  $outputDir
 fi
 
 # build single-frame
 if [[ $target == "all" || $target == "OrthancStoneSingleFrame" ]]; then
   cp $samplesRootDir/Web/single-frame.html $outputDir
-  tsc --allowJs --project $samplesRootDir/Web/single-frame.tsconfig.json
-  cp $currentDir/build-wasm/OrthancStoneSingleFrame.js  $outputDir
-  cp $currentDir/build-wasm/OrthancStoneSingleFrame.wasm  $outputDir
+  tsc --project $samplesRootDir/Web/single-frame.tsconfig.json --outDir "$outputDir"
+  browserify \
+      "$outputDir/Platforms/Wasm/wasm-application-runner.js" \
+      "$outputDir/Applications/Samples/Web/single-frame.js" \
+      -o "$outputDir/app-single-frame.js"
+  cp "$currentDir/build-wasm/OrthancStoneSingleFrame.js"  $outputDir
+  cp "$currentDir/build-wasm/OrthancStoneSingleFrame.wasm"  $outputDir
 fi
 
 # build single-frame-editor
 if [[ $target == "all" || $target == "OrthancStoneSingleFrameEditor" ]]; then
   cp $samplesRootDir/Web/single-frame-editor.html $outputDir
-  tsc --allowJs --project $samplesRootDir/Web/single-frame-editor.tsconfig.json
-  cp $currentDir/build-wasm/OrthancStoneSingleFrameEditor.js  $outputDir
-  cp $currentDir/build-wasm/OrthancStoneSingleFrameEditor.wasm  $outputDir
+  tsc --project $samplesRootDir/Web/single-frame-editor.tsconfig.json --outDir "$outputDir"
+  browserify \
+      "$outputDir/Platforms/Wasm/wasm-application-runner.js" \
+      "$outputDir/Applications/Samples/Web/single-frame-editor.js" \
+      -o "$outputDir/app-single-frame-editor.js"
+  cp "$currentDir/build-wasm/OrthancStoneSingleFrameEditor.js"  $outputDir
+  cp "$currentDir/build-wasm/OrthancStoneSingleFrameEditor.wasm"  $outputDir
 fi
 
 # build simple-viewer project
@@ -44,9 +60,15 @@
   mkdir -p $outputDir/simple-viewer/
   cp $samplesRootDir/SimpleViewer/Wasm/simple-viewer.html $outputDir/simple-viewer/
   cp $samplesRootDir/SimpleViewer/Wasm/styles.css $outputDir/simple-viewer/
-  tsc --allowJs --project $samplesRootDir/SimpleViewer/Wasm/tsconfig-simple-viewer.json
-  cp $currentDir/build-wasm/OrthancStoneSimpleViewer.js  $outputDir/simple-viewer/
-  cp $currentDir/build-wasm/OrthancStoneSimpleViewer.wasm  $outputDir/simple-viewer/
+  
+  # the root dir must contain all the source files for the whole project
+  tsc --module commonjs --allowJs --project "$samplesRootDir/SimpleViewer/Wasm/tsconfig-simple-viewer.json" --rootDir "$samplesRootDir/../.." --outDir "$outputDir/simple-viewer/"
+  browserify \
+    "$outputDir/simple-viewer/Platforms/Wasm/wasm-application-runner.js" \
+    "$outputDir/simple-viewer/Applications/Samples/SimpleViewer/Wasm/simple-viewer.js" \
+    -o "$outputDir/simple-viewer/app-simple-viewer.js"
+  cp "$currentDir/build-wasm/OrthancStoneSimpleViewer.js"  "$outputDir/simple-viewer/"
+  cp "$currentDir/build-wasm/OrthancStoneSimpleViewer.wasm"  "$outputDir/simple-viewer/"
 fi
 
 cd $currentDir
--- a/Applications/Samples/samples-library.js	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-// this file contains the JS method you want to expose to C++ code
-
-// mergeInto(LibraryManager.library, {
-//    ScheduleRedraw: function() {
-//      ScheduleRedraw();
-//    }
-//  });
-  
\ No newline at end of file
--- a/Applications/StoneApplicationContext.h	Wed Jan 16 21:08:38 2019 +0100
+++ b/Applications/StoneApplicationContext.h	Mon Feb 11 16:00:04 2019 +0100
@@ -26,6 +26,25 @@
 #include "../Framework/Toolbox/OrthancApiClient.h"
 #include "../Framework/Viewport/WidgetViewport.h"
 
+
+#ifdef _MSC_VER
+  #if _MSC_VER > 1910
+    #define orthanc_override override
+  #else
+    #define orthanc_override
+  #endif
+#elif defined __GNUC__
+  #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+/* Test for GCC > 3.2.0 */
+  #if GCC_VERSION > 40900
+    #define orthanc_override override
+  else
+    #define orthanc_override
+  #endif
+#else
+    #define orthanc_override
+#endif
+
 #include <list>
 
 namespace OrthancStone
--- a/Platforms/Wasm/WasmDelayedCallExecutor.js	Wed Jan 16 21:08:38 2019 +0100
+++ b/Platforms/Wasm/WasmDelayedCallExecutor.js	Mon Feb 11 16:00:04 2019 +0100
@@ -1,7 +1,7 @@
 mergeInto(LibraryManager.library, {
   WasmDelayedCallExecutor_Schedule: function(callable, timeoutInMs/*, payload*/) {
     setTimeout(function() {
-      WasmDelayedCallExecutor_ExecuteCallback(callable/*, payload*/);
+      window.WasmDelayedCallExecutor_ExecuteCallback(callable/*, payload*/);
     }, timeoutInMs);
   }
 });
--- a/Platforms/Wasm/WasmPlatformApplicationAdapter.cpp	Wed Jan 16 21:08:38 2019 +0100
+++ b/Platforms/Wasm/WasmPlatformApplicationAdapter.cpp	Mon Feb 11 16:00:04 2019 +0100
@@ -27,7 +27,7 @@
               printf("Could not parse command: '%s'\n", input.c_str());
             else
               application_.ExecuteCommand(*command);
-        }
+        } 
       }
       catch (StoneException& exc)
       {
--- a/Platforms/Wasm/WasmWebService.js	Wed Jan 16 21:08:38 2019 +0100
+++ b/Platforms/Wasm/WasmWebService.js	Mon Feb 11 16:00:04 2019 +0100
@@ -24,10 +24,10 @@
           // TODO - Is "new Uint8Array()" necessary? This copies the
           // answer to the WebAssembly stack, hence necessitating
           // increasing the TOTAL_STACK parameter of Emscripten
-          WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
+          window.WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
                                        this.response.byteLength, headers, payload);
         } else {
-          WasmWebService_NotifyError(callableFailure, url_, payload);
+          window.WasmWebService_NotifyError(callableFailure, url_, payload);
         }
       }
     }
--- a/Platforms/Wasm/default-library.js	Wed Jan 16 21:08:38 2019 +0100
+++ b/Platforms/Wasm/default-library.js	Mon Feb 11 16:00:04 2019 +0100
@@ -2,10 +2,10 @@
 
 mergeInto(LibraryManager.library, {
   ScheduleWebViewportRedrawFromCpp: function(cppViewportHandle) {
-    ScheduleWebViewportRedraw(cppViewportHandle);
+    window.ScheduleWebViewportRedraw(cppViewportHandle);
   },
   CreateWasmViewportFromCpp: function(htmlCanvasId) {
-    return CreateWasmViewport(htmlCanvasId);
+    return window.CreateWasmViewport(htmlCanvasId);
   },
   // each time the StoneApplication updates its status, it may signal it through this method. i.e, to change the status of a button in the web interface
   UpdateStoneApplicationStatusFromCpp: function(statusUpdateMessage) {
@@ -13,4 +13,3 @@
     UpdateWebApplication(statusUpdateMessage_);
   }
 });
-  
\ No newline at end of file
--- a/Platforms/Wasm/stone-framework-loader.ts	Wed Jan 16 21:08:38 2019 +0100
+++ b/Platforms/Wasm/stone-framework-loader.ts	Mon Feb 11 16:00:04 2019 +0100
@@ -1,96 +1,95 @@
-module Stone {
-    /**
-     * This file contains primitives to interface with WebAssembly and
-     * with the Stone framework.
-     **/
-    
-    export declare type InitializationCallback = () => void;
-    
-    export declare var StoneFrameworkModule : any;
-    
-    //const ASSETS_FOLDER : string = "assets/lib";
-    //const WASM_FILENAME : string = "orthanc-framework";
-    
-    
-    export class Framework
-    {
-      private static singleton_ : Framework = null;
-      private static wasmModuleName_ : string = null;
+/**
+ * This file contains primitives to interface with WebAssembly and
+ * with the Stone framework.
+ **/
+
+export declare type InitializationCallback = () => void;
+
+//export declare var StoneFrameworkModule : any;
+export var StoneFrameworkModule : any;
+
+//const ASSETS_FOLDER : string = "assets/lib";
+//const WASM_FILENAME : string = "orthanc-framework";
+
+export class Framework
+{
+  private static singleton_ : Framework = null;
+  private static wasmModuleName_ : string = null;
+
+  public static Configure(wasmModuleName: string) {
+    this.wasmModuleName_ = wasmModuleName;
+  }
 
-      public static Configure(wasmModuleName: string) {
-        this.wasmModuleName_ = wasmModuleName;
-      }
+  private constructor(verbose : boolean) 
+  {
+    //this.ccall('Initialize', null, [ 'number' ], [ verbose ]);
+  }
+
+  
+  public ccall( name: string,
+                returnType: string,
+                argTypes: Array<string>,
+                argValues: Array<any>) : any
+  {
+    return (<any> window).StoneFrameworkModule.ccall(name, returnType, argTypes, argValues);
+  }
+
+  
+  public cwrap( name: string,
+                returnType: string,
+                argTypes: Array<string>) : any
+  {
+    return (<any> window).StoneFrameworkModule.cwrap(name, returnType, argTypes);
+  }
 
-      private constructor(verbose : boolean) 
-      {
-        //this.ccall('Initialize', null, [ 'number' ], [ verbose ]);
-      }
-    
-      
-      public ccall(name: string,
-                   returnType: string,
-                   argTypes: Array<string>,
-                   argValues: Array<any>) : any
-      {
-        return StoneFrameworkModule.ccall(name, returnType, argTypes, argValues);
-      }
-    
-      
-      public cwrap(name: string,
-                   returnType: string,
-                   argTypes: Array<string>) : any
-      {
-        return StoneFrameworkModule.cwrap(name, returnType, argTypes);
-      }
-    
-      
-      public static GetInstance() : Framework
-      {
-        if (Framework.singleton_ == null) {
-          throw new Error('The WebAssembly module is not loaded yet');
-        } else {
-          return Framework.singleton_;
+  
+  public static GetInstance() : Framework
+  {
+    if (Framework.singleton_ == null) {
+      throw new Error('The WebAssembly module is not loaded yet');
+    } else {
+      return Framework.singleton_;
+    }
+  }
+
+
+  public static Initialize( verbose: boolean,
+                            callback: InitializationCallback)
+  {
+    console.log('Initializing WebAssembly Module');
+
+    // (<any> window).
+    (<any> window).StoneFrameworkModule = {
+      preRun: [ 
+        function() {
+          console.log('Loading the Stone Framework using WebAssembly');
         }
-      }
-      
-    
-      public static Initialize(verbose: boolean,
-                               callback: InitializationCallback)
-      {
-        console.log('Initializing WebAssembly Module');
-    
-        (<any> window).StoneFrameworkModule = {
-          preRun: [ 
-            function() {
-              console.log('Loading the Stone Framework using WebAssembly');
-            }
-          ],
-          postRun: [ 
-            function()  {
-              // This function is called by ".js" wrapper once the ".wasm"
-              // WebAssembly module has been loaded and compiled by the
-              // browser
-              console.log('WebAssembly is ready');
-              Framework.singleton_ = new Framework(verbose);
-              callback();
-            }
-          ],
-          print: function(text : string) {
-            console.log(text);
-          },
-          printErr: function(text : string) {
-            console.error(text);
-          },
-          totalDependencies: 0
-        };
-    
-        // Dynamic loading of the JavaScript wrapper around WebAssembly
-        var script = document.createElement('script');
-        script.type = 'application/javascript';
-        //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
-        script.src = this.wasmModuleName_ + ".js";//  "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
-        script.async = true;
-        document.head.appendChild(script);
-      }
-    }
-}
\ No newline at end of file
+      ],
+      postRun: [ 
+        function()  {
+          // This function is called by ".js" wrapper once the ".wasm"
+          // WebAssembly module has been loaded and compiled by the
+          // browser
+          console.log('WebAssembly is ready');
+          Framework.singleton_ = new Framework(verbose);
+          callback();
+        }
+      ],
+      print: function(text : string) {
+        console.log(text);
+      },
+      printErr: function(text : string) {
+        console.error(text);
+      },
+      totalDependencies: 0
+    };
+
+    // Dynamic loading of the JavaScript wrapper around WebAssembly
+    var script = document.createElement('script');
+    script.type = 'application/javascript';
+    //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
+    script.src = this.wasmModuleName_ + ".js";//  "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
+    script.async = true;
+    document.head.appendChild(script);
+  }
+}
--- a/Platforms/Wasm/wasm-application-runner.ts	Wed Jan 16 21:08:38 2019 +0100
+++ b/Platforms/Wasm/wasm-application-runner.ts	Mon Feb 11 16:00:04 2019 +0100
@@ -1,11 +1,12 @@
-///<reference path='stone-framework-loader.ts'/>
-///<reference path='wasm-viewport.ts'/>
+import Stone = require('./stone-framework-loader');
+import StoneViewport = require('./wasm-viewport');
 
 if (!('WebAssembly' in window)) {
   alert('Sorry, your browser does not support WebAssembly :(');
 }
 
-declare var StoneFrameworkModule : Stone.Framework;
+//var StoneFrameworkModule : Stone.Framework = (<any>window).StoneFrameworkModule;
+//export declare var StoneFrameworkModule : Stone.Framework;
 
 // global functions
 var WasmWebService_NotifyError: Function = null;
@@ -15,11 +16,10 @@
 var WasmDoAnimation: Function = null;
 var SetStartupParameter: Function = null;
 var CreateWasmApplication: Function = null;
-var CreateCppViewport: Function = null;
+export var CreateCppViewport: Function = null;
 var ReleaseCppViewport: Function = null;
 var StartWasmApplication: Function = null;
-var SendMessageToStoneApplication: Function = null;
-
+export var SendMessageToStoneApplication: Function = null;
 
 function DoAnimationThread() {
   if (WasmDoAnimation != null) {
@@ -29,7 +29,6 @@
   setTimeout(DoAnimationThread, 100);  // Update the viewport content every 100ms if need be
 }
 
-
 function GetUriParameters(): Map<string, string> {
   var parameters = window.location.search.substr(1);
 
@@ -72,12 +71,12 @@
   StartWasmApplication(orthancBaseUrl);
 
   // trigger a first resize of the canvas that has just been initialized
-  Stone.WasmViewport.ResizeAll();
+  StoneViewport.WasmViewport.ResizeAll();
 
   DoAnimationThread();
 }
 
-function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) {
+export function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) {
   
   Stone.Framework.Configure(wasmModuleName);
 
@@ -87,19 +86,20 @@
 
     console.log("Connecting C++ methods to JS methods");
     
-    SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']);
-    CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']);
-    CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []);
-    ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']);
-    StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']);
+    SetStartupParameter = (<any> window).StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']);
+    CreateWasmApplication = (<any> window).StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']);
+    CreateCppViewport = (<any> window).StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []);
+    ReleaseCppViewport = (<any> window).StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']);
+    StartWasmApplication = (<any> window).StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']);
 
-    WasmWebService_NotifyCachedSuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']);
-    WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']);
-    WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']);
-    WasmDelayedCallExecutor_ExecuteCallback = StoneFrameworkModule.cwrap('WasmDelayedCallExecutor_ExecuteCallback', null, ['number']);
-    WasmDoAnimation = StoneFrameworkModule.cwrap('WasmDoAnimation', null, []);
+    (<any> window).WasmWebService_NotifyCachedSuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']);
+    (<any> window).WasmWebService_NotifySuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']);
+    (<any> window).WasmWebService_NotifyError = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']);
+    (<any> window).WasmDelayedCallExecutor_ExecuteCallback = (<any> window).StoneFrameworkModule.cwrap('WasmDelayedCallExecutor_ExecuteCallback', null, ['number']);
+    // no need to put this into the globals for it's only used in this very module
+    WasmDoAnimation = (<any> window).StoneFrameworkModule.cwrap('WasmDoAnimation', null, []);
 
-    SendMessageToStoneApplication = StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']);
+    SendMessageToStoneApplication = (<any> window).StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']);
 
     console.log("Connecting C++ methods to JS methods - done");
 
@@ -110,4 +110,10 @@
 
     _InitializeWasmApplication(orthancBaseUrl);
   });
-}
\ No newline at end of file
+}
+
+
+// exports.InitializeWasmApplication = InitializeWasmApplication;
+
+
+
--- a/Platforms/Wasm/wasm-viewport.ts	Wed Jan 16 21:08:38 2019 +0100
+++ b/Platforms/Wasm/wasm-viewport.ts	Mon Feb 11 16:00:04 2019 +0100
@@ -1,3 +1,6 @@
+import wasmApplicationRunner = require('./wasm-application-runner');
+//import stoneFrameworkLoader = require('./stone-framework-loader');
+
 var isPendingRedraw = false;
 
 function ScheduleWebViewportRedraw(cppViewportHandle: any) : void
@@ -7,24 +10,26 @@
     console.log('Scheduling a refresh of the viewport, as its content changed');
     window.requestAnimationFrame(function() {
       isPendingRedraw = false;
-      Stone.WasmViewport.GetFromCppViewport(cppViewportHandle).Redraw();
+      WasmViewport.GetFromCppViewport(cppViewportHandle).Redraw();
     });
   }
 }
 
+(<any>window).ScheduleWebViewportRedraw = ScheduleWebViewportRedraw;
+
 declare function UTF8ToString(any): string;
 
 function CreateWasmViewport(htmlCanvasId: string) : any {
-  var cppViewportHandle = CreateCppViewport();
+  var cppViewportHandle = wasmApplicationRunner.CreateCppViewport();
   var canvasId = UTF8ToString(htmlCanvasId);
-  var webViewport = new Stone.WasmViewport(StoneFrameworkModule, canvasId, cppViewportHandle);  // viewports are stored in a static map in WasmViewport -> won't be deleted
+  var webViewport = new WasmViewport((<any> window).StoneFrameworkModule, canvasId, cppViewportHandle);  // viewports are stored in a static map in WasmViewport -> won't be deleted
   webViewport.Initialize();
 
   return cppViewportHandle;
 }
+ 
+(<any>window).CreateWasmViewport = CreateWasmViewport;
 
-module Stone {
-  
 //  export declare type InitializationCallback = () => void;
   
 //  export declare var StoneFrameworkModule : any;
@@ -32,7 +37,7 @@
   //const ASSETS_FOLDER : string = "assets/lib";
   //const WASM_FILENAME : string = "orthanc-framework";
 
-  export class WasmViewport {
+export class WasmViewport {
 
     private static viewportsMapByCppHandle_ : Map<number, WasmViewport> = new Map<number, WasmViewport>(); // key = the C++ handle
     private static viewportsMapByCanvasId_ : Map<string, WasmViewport> = new Map<string, WasmViewport>(); // key = the canvasId
@@ -291,5 +296,5 @@
   }
     
 }
-}
+
   
\ No newline at end of file
--- a/README.md	Wed Jan 16 21:08:38 2019 +0100
+++ b/README.md	Mon Feb 11 16:00:04 2019 +0100
@@ -80,6 +80,8 @@
 in `~/apps/emsdk`. If you wish to use it in another way, please edit
 the `build-wasm.sh` file.
 
+ninja (`sudo apt-get install -y ninja-build`) is used instead of make, for performance reasons.
+
 Installation and usage ----------------------
 
 Build instructions are similar to that of Orthanc:
--- a/Resources/CMake/FlatBuffersConfiguration.cmake	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,171 +0,0 @@
-# Stone of Orthanc
-# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
-# Department, University Hospital of Liege, Belgium
-# Copyright (C) 2017-2019 Osimis S.A., Belgium
-#
-# This program is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Affero General Public License
-# as published by the Free Software Foundation, either version 3 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Affero General Public License for more details.
-# 
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake)
-set(FLATC_AUTOGENERATED_SOURCES)
-
-if (STATIC_BUILD OR NOT USE_SYSTEM_FLATBUFFERS)
-  SET(FLATBUFFERS_SOURCES_DIR ${CMAKE_BINARY_DIR}/flatbuffers-1.10)
-  SET(FLATBUFFERS_URL "http://127.0.0.1:8000/flatbuffers-1.10.tar.gz")
-  SET(FLATBUFFERS_MD5 "d5f131809c14def9682d49385b452e43")
-
-  DownloadPackage(${FLATBUFFERS_MD5} ${FLATBUFFERS_URL} "${FLATBUFFERS_SOURCES_DIR}")
-
-  include_directories(${FLATBUFFERS_SOURCES_DIR}/include)
-
-  # we only need the flatc compiler!
-  set(FLATBUFFERS_BUILD_TESTS OFF)
-  set(FLATBUFFERS_INSTALL OFF)
-  set(FLATBUFFERS_BUILD_FLATLIB OFF)
-  set(FLATBUFFERS_BUILD_FLATC ON)
-  set(FLATBUFFERS_BUILD_FLATHASH OFF)
-  set(FLATBUFFERS_BUILD_GRPCTEST OFF)
-  set(FLATBUFFERS_BUILD_SHAREDLIB OFF)
-  set(FLATBUFFERS_LIBCXX_WITH_CLANG OFF)
-
-  # add_subdirectory(${FLATBUFFERS_SOURCES_DIR}
-  #    ${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build
-  #    EXCLUDE_FROM_ALL)
-
-  # Now simply link against flatbuffers as needed to your already declared target.
-  # The flatbuffers target carry header search path automatically if CMake > 2.8.11.
-  #target_link_libraries(own_project_target PRIVATE flatbuffers)
-
-else()
-  find_package(FlatBuffers)
-  include_directories(${SDL2_INCLUDE_DIRS})
-  link_libraries(${SDL2_LIBRARIES})
-endif()
-
-macro(GetFilenameFromPath TargetVariable Path)
-  #message(STATUS "GetFilenameFromPath (1): Path = ${Path} TargetVariable = ${${TargetVariable}}")
-  string(REPLACE "\\" "/" PathWithFwdSlashes "${Path}")
-  string(REGEX REPLACE "^.*/" "" ${TargetVariable} "${PathWithFwdSlashes}")
-  #message(STATUS "GetFilenameFromPath (2): Path = ${Path} Path = ${PathWithFwdSlashes} TargetVariable = ${TargetVariable}")
-endmacro()
-
-macro(GetFilePathWithoutLastExtension TargetVariable FilePath)
-  string(REGEX REPLACE "(^.*)\\.([^\\.]+)" "\\1" ${TargetVariable} "${FilePath}")
-  #message(STATUS "GetFileNameWithoutLastExtension: FilePath = ${FilePath} TargetVariable = ${${TargetVariable}}")
-endmacro()
-
-macro(Test_GetFilePathWithoutLastExtension)
-  set(tmp "/prout/zi/goui.goui.cpp")
-  GetFilePathWithoutLastExtension(TargetVariable "${tmp}")
-  if(NOT ("${TargetVariable}" STREQUAL "/prout/zi/goui.goui"))
-    message(FATAL_ERROR "Test_GetFilePathWithoutLastExtension failed (1)")
-  else()
-    #message(STATUS "Test_GetFilePathWithoutLastExtension: <<OK>>")
-  endif()
-endmacro()
-
-Test_GetFilePathWithoutLastExtension()
-
-macro(Test_GetFilenameFromPath)
-  set(tmp "/prout/../../dada/zi/goui.goui.cpp")
-  GetFilenameFromPath(TargetVariable "${tmp}")
-  if(NOT ("${TargetVariable}" STREQUAL "goui.goui.cpp"))
-    message(FATAL_ERROR "Test_GetFilenameFromPath failed")
-  else()
-    #message(STATUS "Test_GetFilenameFromPath: <<OK>>")
-  endif()
-endmacro()
-
-Test_GetFilenameFromPath()
-
-macro(GenerateCodeFromFlatBufferSchema schemaFilePath)
-  # extract file name
-  GetFilePathWithoutLastExtension(schemaFilePathWithoutExt ${schemaFilePath})
-  
-  # remove extension
-  GetFilenameFromPath(schemaFileNameWithoutExt ${schemaFilePathWithoutExt})
-  
-  set(generatedFilePathWithoutExtension "${CMAKE_BINARY_DIR}/${schemaFileNameWithoutExt}_generated")
-  set(generatedCppFileName "${generatedFilePathWithoutExtension}.h")
-  set(generatedTsFileName "${generatedFilePathWithoutExtension}.ts")
-  set(generatedJsFileName "${generatedFilePathWithoutExtension}.js")
-
-  set(AUTOGENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED")
-  set(AUTOGENERATED_SOURCES)
-  
-  set(FLATC_EXECUTABLE "flatc")
-  find_program(FLATC_EXECUTABLE_SEARCH ${FLATC_EXECUTABLE})
-  if(NOT FLATC_EXECUTABLE_SEARCH)
-    message(FATAL_ERROR "FlatBuffers compiler not found")
-  endif()
-
-  set(SCRIPT_CPP_OPTIONS)
-  list(APPEND SCRIPT_CPP_OPTIONS "--gen-object-api")
-  list(APPEND SCRIPT_CPP_OPTIONS "--cpp")
-  list(APPEND SCRIPT_CPP_OPTIONS "--gen-onefile")
-  list(APPEND SCRIPT_CPP_OPTIONS "--gen-all")
-  list(APPEND SCRIPT_CPP_OPTIONS "--force-empty")
-  list(APPEND SCRIPT_CPP_OPTIONS "--reflect-types")
-  list(APPEND SCRIPT_CPP_OPTIONS "--reflect-names")
-
-  set(SCRIPT_TS_OPTIONS)
-  list(APPEND SCRIPT_TS_OPTIONS "--gen-object-api")
-  list(APPEND SCRIPT_TS_OPTIONS "--ts")
-  list(APPEND SCRIPT_TS_OPTIONS "--gen-onefile")
-  list(APPEND SCRIPT_TS_OPTIONS "--gen-all")
-  list(APPEND SCRIPT_TS_OPTIONS "--no-js-exports")
-  list(APPEND SCRIPT_TS_OPTIONS "--force-empty")
-  list(APPEND SCRIPT_TS_OPTIONS "--reflect-types")
-  list(APPEND SCRIPT_TS_OPTIONS "--reflect-names")
-
-  set(SCRIPT_JS_OPTIONS)
-  list(APPEND SCRIPT_JS_OPTIONS "--gen-object-api")
-  list(APPEND SCRIPT_JS_OPTIONS "--js")
-  list(APPEND SCRIPT_JS_OPTIONS "--gen-onefile")
-  list(APPEND SCRIPT_JS_OPTIONS "--gen-all")
-  list(APPEND SCRIPT_JS_OPTIONS "--no-js-exports")
-  list(APPEND SCRIPT_JS_OPTIONS "--force-empty")
-  list(APPEND SCRIPT_JS_OPTIONS "--reflect-types")
-  list(APPEND SCRIPT_JS_OPTIONS "--reflect-names")
-
-  add_custom_command(
-    OUTPUT
-    ${generatedCppFileName}
-    COMMAND 
-    ${FLATC_EXECUTABLE} ${SCRIPT_CPP_OPTIONS} ${schemaFilePath}
-    DEPENDS
-    ${schemaFilePath}
-    )
-  
-  add_custom_command(
-    OUTPUT
-    ${generatedTsFileName}
-    COMMAND 
-    ${FLATC_EXECUTABLE} ${SCRIPT_TS_OPTIONS} ${schemaFilePath}
-    DEPENDS
-    ${schemaFilePath}
-    )
-  
-  add_custom_command(
-    OUTPUT
-    ${generatedJsFileName}
-    COMMAND 
-    ${FLATC_EXECUTABLE} ${SCRIPT_JS_OPTIONS} ${schemaFilePath}
-    DEPENDS
-    ${schemaFilePath}
-    )
-
-    list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedCppFileName}") 
-    list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedJsFileName}") 
-    list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedTsFileName}") 
-
-endmacro()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CMake/ProtobufCodeGeneration.cmake	Mon Feb 11 16:00:04 2019 +0100
@@ -0,0 +1,77 @@
+# HOW TO USE:
+# the GenerateCodeFromProtobufSchema will generate files in ${CMAKE_BINARY_DIR} and will
+# populate PROTOBUF_AUTOGENERATED_SOURCES with the list of generated files
+# AS OF 2019-01-30, it requires protoc (version 3.6.1.x) to be available in the path
+set(PROTOBUF_AUTOGENERATED_SOURCES)
+
+# TODO: use find_program (<VAR> name1 [path1 path2 ...]) to located the protobuf compiler
+# TODO: automated the TS plugin installation
+
+macro(GenerateCodeFromProtobufSchema schemaFilePath outputBaseDirectory)
+  # extract file name
+  GetFilePathWithoutLastExtension(schemaFilePathWithoutExt ${schemaFilePath})
+  
+  # remove extension
+  GetFilenameFromPath(schemaFileNameWithoutExt ${schemaFilePathWithoutExt})
+  
+  set(generatedFilePathWithoutExtension "${CMAKE_BINARY_DIR}/AUTOGENERATED/${schemaFileNameWithoutExt}")
+  set(generatedCppSourceFilePath "${generatedFilePathWithoutExtension}.pb.cc")
+  set(generatedCppHeaderFilePath "${generatedFilePathWithoutExtension}.pb.h")
+  set(generatedJsFilePath "${generatedFilePathWithoutExtension}_pb.js")
+  set(generatedTsFilePath "${generatedFilePathWithoutExtension}_pb.d.ts")
+  # set(generatedJsFileName "${generatedFilePathWithoutExtension}.js")
+
+  # set(AUTOGENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED")
+  # set(AUTOGENERATED_SOURCES)
+  
+  set(PROTOC_EXECUTABLE "PROTOC")
+  find_program(PROTOC_EXECUTABLE_SEARCH ${FLATC_EXECUTABLE})
+  if(NOT PROTOC_EXECUTABLE_SEARCH)
+    message(FATAL_ERROR "The Protocol Buffers compiler (protoc[.exe]) cannot be found!")
+  endif()
+
+  # TODO CUSTOMIZE FOR TYPESCRIPT
+  set(SCRIPT_CPP_OPTIONS)
+  list(APPEND SCRIPT_CPP_OPTIONS "----cpp_out=${CMAKE_BINARY_DIR}/AUTOGENERATED")
+  # list(APPEND SCRIPT_CPP_OPTIONS "gnagna")
+  
+  set(SCRIPT_TS_OPTIONS)
+
+  list(APPEND SCRIPT_TS_OPTIONS "--ts")
+  list(APPEND SCRIPT_TS_OPTIONS "gnagna")
+
+  add_custom_command(
+    OUTPUT
+    ${generatedCppSourceFilePath}
+    ${generatedCppHeaderFilePath}
+    COMMAND 
+    ${PROTOC_EXECUTABLE} ${SCRIPT_CPP_OPTIONS} ${schemaFilePath}
+    DEPENDS
+    ${schemaFilePath}
+    )
+  
+  add_custom_command(
+    OUTPUT
+    ${generatedTsFileName}
+    ${generatedJsFilePath}
+    COMMAND 
+    ${PROTOC_EXECUTABLE} ${SCRIPT_TS_OPTIONS} ${schemaFilePath}
+    DEPENDS
+    ${schemaFilePath}
+    )
+  
+  # add_custom_command(
+  #   OUTPUT
+  #   ${generatedJsFileName}
+  #   COMMAND 
+  #   ${FLATC_EXECUTABLE} ${SCRIPT_JS_OPTIONS} ${schemaFilePath}
+  #   DEPENDS
+  #   ${schemaFilePath}
+  #   )
+
+    list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedCppFileName}") 
+    # list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedJsFileName}") 
+    list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedTsFileName}") 
+
+endmacro()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CMake/Utilities.cmake	Mon Feb 11 16:00:04 2019 +0100
@@ -0,0 +1,37 @@
+
+
+macro(GetFilenameFromPath TargetVariable Path)
+#message(STATUS "GetFilenameFromPath (1): Path = ${Path} TargetVariable = ${${TargetVariable}}")
+string(REPLACE "\\" "/" PathWithFwdSlashes "${Path}")
+string(REGEX REPLACE "^.*/" "" ${TargetVariable} "${PathWithFwdSlashes}")
+#message(STATUS "GetFilenameFromPath (2): Path = ${Path} Path = ${PathWithFwdSlashes} TargetVariable = ${TargetVariable}")
+endmacro()
+
+macro(GetFilePathWithoutLastExtension TargetVariable FilePath)
+string(REGEX REPLACE "(^.*)\\.([^\\.]+)" "\\1" ${TargetVariable} "${FilePath}")
+#message(STATUS "GetFileNameWithoutLastExtension: FilePath = ${FilePath} TargetVariable = ${${TargetVariable}}")
+endmacro()
+
+macro(Test_GetFilePathWithoutLastExtension)
+set(tmp "/prout/zi/goui.goui.cpp")
+GetFilePathWithoutLastExtension(TargetVariable "${tmp}")
+if(NOT ("${TargetVariable}" STREQUAL "/prout/zi/goui.goui"))
+  message(FATAL_ERROR "Test_GetFilePathWithoutLastExtension failed (1)")
+else()
+  #message(STATUS "Test_GetFilePathWithoutLastExtension: <<OK>>")
+endif()
+endmacro()
+
+Test_GetFilePathWithoutLastExtension()
+
+macro(Test_GetFilenameFromPath)
+set(tmp "/prout/../../dada/zi/goui.goui.cpp")
+GetFilenameFromPath(TargetVariable "${tmp}")
+if(NOT ("${TargetVariable}" STREQUAL "goui.goui.cpp"))
+  message(FATAL_ERROR "Test_GetFilenameFromPath failed")
+else()
+  #message(STATUS "Test_GetFilenameFromPath: <<OK>>")
+endif()
+endmacro()
+
+Test_GetFilenameFromPath()
--- a/Resources/CommandTool/flatc-tests/basic/BasicCommands.fbs	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-// Example IDL file for our monster's schema.
-namespace Orthanc.Stone.Applications;
-
-union BasicCommands = {SelectTool, PanImage}
-union BasicReplies = {SelectToolReply, PanImageReply, LoadFileReply }
-
-table SelectTool {
-  tool:Tool;
-}
-
-table SelectToolReply {
-}
-
-table PanImage {
-  x:int32;
-  y:int32;
-}
-
-table PanImageReply {
-  x:int32;
-  y:int32;
-}
-
-table LoadFile {
-  filePath:string;
-}
-
-table LoadFileReply {
-  success:bool;
-}
-
-union BasicCommand {
-  command: BasicCommands
-}
-
-union BasicReply {
-  command: BasicReplies
-}
-
-// root_type Monster;
-
--- a/Resources/CommandTool/flatc-tests/basic/CMakeLists.txt	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-cmake_minimum_required(VERSION 2.8.3)
-
-project(BasicFlatBuffersTest)
-
-set(AUTOGENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED")
-set(AUTOGENERATED_SOURCES)
-
-set(FLATC_EXECUTABLE "flatc")
-
-set(DEPOT_ROOT "/osimis")
-
-set(SCRIPT_CPP_OPTIONS)
-list(APPEND SCRIPT_CPP_OPTIONS "--gen-object-api")
-list(APPEND SCRIPT_CPP_OPTIONS "--cpp")
-list(APPEND SCRIPT_CPP_OPTIONS "--gen-onefile")
-list(APPEND SCRIPT_CPP_OPTIONS "--gen-all")
-list(APPEND SCRIPT_CPP_OPTIONS "--force-empty")
-list(APPEND SCRIPT_CPP_OPTIONS "--reflect-types")
-list(APPEND SCRIPT_CPP_OPTIONS "--reflect-names")
-
-set(SCRIPT_TS_OPTIONS)
-list(APPEND SCRIPT_TS_OPTIONS "--gen-object-api")
-list(APPEND SCRIPT_TS_OPTIONS "--ts")
-list(APPEND SCRIPT_TS_OPTIONS "--gen-onefile")
-list(APPEND SCRIPT_TS_OPTIONS "--gen-all")
-list(APPEND SCRIPT_TS_OPTIONS "--no-js-exports")
-list(APPEND SCRIPT_TS_OPTIONS "--force-empty")
-list(APPEND SCRIPT_TS_OPTIONS "--reflect-types")
-list(APPEND SCRIPT_TS_OPTIONS "--reflect-names")
-
-set(SCRIPT_JS_OPTIONS)
-list(APPEND SCRIPT_JS_OPTIONS "--gen-object-api")
-list(APPEND SCRIPT_JS_OPTIONS "--js")
-list(APPEND SCRIPT_JS_OPTIONS "--gen-onefile")
-list(APPEND SCRIPT_JS_OPTIONS "--gen-all")
-list(APPEND SCRIPT_JS_OPTIONS "--no-js-exports")
-list(APPEND SCRIPT_JS_OPTIONS "--force-empty")
-list(APPEND SCRIPT_JS_OPTIONS "--reflect-types")
-list(APPEND SCRIPT_JS_OPTIONS "--reflect-names")
-
-set(SCHEMA_FILE "${CMAKE_CURRENT_LIST_DIR}/basic.fbs")
-set(AUTOGENERATED_CPP_FILE "${CMAKE_BINARY_DIR}/basic_generated.h")
-set(AUTOGENERATED_TS_FILE "${CMAKE_BINARY_DIR}/basic_generated.ts")
-set(AUTOGENERATED_JS_FILE "${CMAKE_BINARY_DIR}/basic_generated.js")
-
-add_custom_command(
-  OUTPUT
-  ${AUTOGENERATED_CPP_FILE}
-  COMMAND 
-  ${FLATC_EXECUTABLE} ${SCRIPT_CPP_OPTIONS} ${SCHEMA_FILE}
-  DEPENDS
-  ${SCHEMA_FILE}
-  )
-
-add_custom_command(
-  OUTPUT
-  ${AUTOGENERATED_TS_FILE}
-  COMMAND 
-  ${FLATC_EXECUTABLE} ${SCRIPT_TS_OPTIONS} ${SCHEMA_FILE}
-  DEPENDS
-  ${SCHEMA_FILE}
-  )
-
-add_custom_command(
-  OUTPUT
-  ${AUTOGENERATED_JS_FILE}
-  COMMAND 
-  ${FLATC_EXECUTABLE} ${SCRIPT_JS_OPTIONS} ${SCHEMA_FILE}
-  DEPENDS
-  ${SCHEMA_FILE}
-  )
-
-list(APPEND AUTOGENERATED_SOURCES ${AUTOGENERATED_CPP_FILE} ${AUTOGENERATED_TS_FILE} ${AUTOGENERATED_JS_FILE})
-
-message("AUTOGENERATED_SOURCES = ${AUTOGENERATED_SOURCES}")
-add_executable(BasicFlatBuffersTest main.cpp ${SCHEMA_FILE} ${AUTOGENERATED_SOURCES})
-
-target_include_directories(BasicFlatBuffersTest PRIVATE ${DEPOT_ROOT}/ThirdParty/flatbuffers-1.10/include)
-target_include_directories(BasicFlatBuffersTest PRIVATE ${CMAKE_BINARY_DIR})
--- a/Resources/CommandTool/flatc-tests/basic/basic_test_gen.ps1	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-flatc --gen-object-api --cpp .\basic.fbs
-flatc --ts .\basic.fbs
\ No newline at end of file
--- a/Resources/CommandTool/flatc-tests/basic/main.cpp	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-#include <iostream>
-#include "basic_generated.h"
-
-using namespace Orthanc::Stone::Samples::SimpleViewer;
-
-namespace OrthancStone
-{
-    class IPocMessage
-    {
-    public:
-        virtual std::string GetType() = 0;
-    };
-
-
-}
-
-
-
-int main()
-{
-    Request;
-
-    Request::messageType = SelectTool;
-
-    SelectToolT tool2;
-    tool2.tool = Tool_CircleMeasure;
-    
-    SendToApplication(tool2);
-    
-
-    tool2.tool = Tool_CircleMeasure;
-
-    CircleToolT circleTool;
-    circleTool.centerX = 3;
-    circleTool.centerY = 4;
-
-    std::cout << "Hello from flatc generator sample!" << std::endl;
-}
--- a/Resources/CommandTool/protoc-tests/basic.proto	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-syntax = "proto3";
-
-// Taken from https://developers.google.com/protocol-buffers/docs/proto
-message SearchRequest {
-    string query = 1;
-    int32 page_number = 2;
-    int32 result_per_page = 3;
-}
-
--- a/Resources/CommandTool/protoc-tests/basic_js_test.ps1	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-# Path to this plugin 
-
-# Under Linux
-# $PROTOC_GEN_TS_PATH="$PSScriptRoot/node_modules/.bin/protoc-gen-ts"
-
-# Under Windows
-
-# Directory to write generated code to (.js and .d.ts files) 
-$OUT_DIR="./generated_js"
- 
-protoc `
-    --js_out="$OUT_DIR" `
-    basic.proto
-
-
--- a/Resources/CommandTool/protoc-tests/basic_test.html	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-<html>
-<head>
-<title>Notepad</title>
-<script src='https://cdn.rawgit.com/google/closure-library/master/closure/goog/base.js'></script>
-<script src="generated_js/searchrequest.js"></script>
-</head>
-<body>
-
-<div id="notes">
-</div>
-
-<script>
-function main() {
-  var noteData = [
-    {'title': 'Note 1', 'content': 'Content of Note 1'},
-    {'title': 'Note 2', 'content': 'Content of Note 2'}];
-
-  var noteListElement = document.getElementById('notes');
-  var notes = proto.SearchRequest(1);
-}
-main();
-</script>
-</body>
-</html>
\ No newline at end of file
--- a/Resources/CommandTool/protoc-tests/basic_ts_test.ps1	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-# Path to this plugin 
-
-# Under Linux
-# $PROTOC_GEN_TS_PATH="$PSScriptRoot/node_modules/.bin/protoc-gen-ts"
-
-# Under Windows
-$PROTOC_GEN_TS_PATH="$PSScriptRoot/node_modules/.bin/protoc-gen-ts.cmd"
-
-# Directory to write generated code to (.js and .d.ts files) 
-$OUT_DIR="./generated_ts"
- 
-protoc `
-    --plugin="protoc-gen-ts=$PROTOC_GEN_TS_PATH" `
-    --js_out="import_style=commonjs,binary:$OUT_DIR" `
-    --ts_out="$OUT_DIR" `
-    basic.proto
-
-
--- a/Resources/CommandTool/protoc-tests/package-lock.json	Wed Jan 16 21:08:38 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-{
-  "requires": true,
-  "lockfileVersion": 1,
-  "dependencies": {
-    "google-protobuf": {
-      "version": "3.6.1",
-      "resolved": "https://registry.npmjs.org/google-protobuf/-/google-protobuf-3.6.1.tgz",
-      "integrity": "sha512-SJYemeX5GjDLPnadcmCNQePQHCS4Hl5fOcI/JawqDIYFhCmrtYAjcx/oTQx/Wi8UuCuZQhfvftbmPePPAYHFtA=="
-    },
-    "ts-protoc-gen": {
-      "version": "0.9.0",
-      "resolved": "https://registry.npmjs.org/ts-protoc-gen/-/ts-protoc-gen-0.9.0.tgz",
-      "integrity": "sha512-cFEUTY9U9o6C4DPPfMHk2ZUdIAKL91hZN1fyx5Stz3g56BDVOC7hk+r5fEMCAGaaIgi2akkT1a2hrxu1wo2Phg=="
-    }
-  }
-}