# HG changeset patch # User Sebastien Jodogne # Date 1762277139 -3600 # Node ID 2beac4eb0722dd0f37121ab4856a8bc1a38f44f9 # Parent b0f4843da0fa7604232956c6791869d91e029660 add standalone build for the viewer plugin diff -r b0f4843da0fa -r 2beac4eb0722 Resources/CMake/JavaScriptLibraries.cmake --- a/Resources/CMake/JavaScriptLibraries.cmake Tue Nov 04 18:04:57 2025 +0100 +++ b/Resources/CMake/JavaScriptLibraries.cmake Tue Nov 04 18:25:39 2025 +0100 @@ -26,11 +26,14 @@ "${BASE_URL}/WSI/openlayers-10.6.1-package.tar.gz" "openlayers-10.6.1-package") + set(JAVASCRIPT_LIBS_DIR ${CMAKE_CURRENT_BINARY_DIR}/javascript-libs) file(MAKE_DIRECTORY ${JAVASCRIPT_LIBS_DIR}) + file(COPY ${CMAKE_CURRENT_BINARY_DIR}/openlayers-10.6.1-package/dist/ol.js + ${CMAKE_CURRENT_BINARY_DIR}/openlayers-10.6.1-package/dist/ol.js.map DESTINATION ${JAVASCRIPT_LIBS_DIR}/js ) diff -r b0f4843da0fa -r 2beac4eb0722 ViewerPlugin/CMakeLists.txt --- a/ViewerPlugin/CMakeLists.txt Tue Nov 04 18:04:57 2025 +0100 +++ b/ViewerPlugin/CMakeLists.txt Tue Nov 04 18:25:39 2025 +0100 @@ -32,6 +32,7 @@ # Generic parameters SET(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") SET(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages") +SET(STANDALONE_BUILD ON CACHE BOOL "Standalone build (all the resources are embedded, necessary for releases)") # Advanced parameters to fine-tune linking against system libraries SET(USE_SYSTEM_OPENJPEG ON CACHE BOOL "Use the system version of OpenJpeg") @@ -146,11 +147,23 @@ include(${CMAKE_SOURCE_DIR}/../Resources/CMake/JavaScriptLibraries.cmake) +if (STANDALONE_BUILD) + add_definitions(-DORTHANC_STANDALONE=1) + set(VIEWER_RESOURCES + VIEWER_HTML ${CMAKE_SOURCE_DIR}/viewer.html + VIEWER_JS ${CMAKE_SOURCE_DIR}/viewer.js + ) +else() + add_definitions( + -DORTHANC_STANDALONE=0 + -DPLUGIN_SOURCE_DIR="${CMAKE_SOURCE_DIR}" + ) +endif() + EmbedResources( + ${VIEWER_RESOURCES} JAVASCRIPT_LIBS ${JAVASCRIPT_LIBS_DIR} ORTHANC_EXPLORER ${CMAKE_SOURCE_DIR}/OrthancExplorer.js - VIEWER_HTML ${CMAKE_SOURCE_DIR}/viewer.html - VIEWER_JS ${CMAKE_SOURCE_DIR}/viewer.js MIRADOR_HTML ${CMAKE_SOURCE_DIR}/mirador.html OPEN_SEADRAGON_HTML ${CMAKE_SOURCE_DIR}/openseadragon.html ) diff -r b0f4843da0fa -r 2beac4eb0722 ViewerPlugin/Plugin.cpp --- a/ViewerPlugin/Plugin.cpp Tue Nov 04 18:04:57 2025 +0100 +++ b/ViewerPlugin/Plugin.cpp Tue Nov 04 18:25:39 2025 +0100 @@ -392,9 +392,9 @@ } -void ServeFile(OrthancPluginRestOutput* output, - const char* url, - const OrthancPluginHttpRequest* request) +void ServeEmbeddedFile(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) { Orthanc::EmbeddedResources::FileResourceId resource; @@ -403,12 +403,22 @@ if (f == "viewer.html") { +#if ORTHANC_STANDALONE == 0 + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); +#else resource = Orthanc::EmbeddedResources::VIEWER_HTML; +#endif + mime = "text/html"; } else if (f == "viewer.js") { +#if ORTHANC_STANDALONE == 0 + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); +#else resource = Orthanc::EmbeddedResources::VIEWER_JS; +#endif + mime = "application/javascript"; } else if (f == "mirador.html") @@ -433,6 +443,33 @@ } +#if ORTHANC_STANDALONE == 0 +void ServeSourceFile(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) +{ + // This method should only be used during the development to speed up compilation + + std::string filename(request->groups[0]); + + if (filename != "viewer.html" && + filename != "viewer.js") + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); + } + + const boost::filesystem::path path = Orthanc::SystemToolbox::InterpretRelativePath( + Orthanc::SystemToolbox::PathFromUtf8(PLUGIN_SOURCE_DIR), filename); + const char* mime = Orthanc::EnumerationToString(Orthanc::SystemToolbox::AutodetectMimeType(filename)); + + std::string content; + Orthanc::SystemToolbox::ReadFile(content, path); + + OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, content.c_str(), content.size(), mime); +} +#endif + + extern "C" { ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) @@ -538,8 +575,15 @@ OrthancPluginRegisterOnChangeCallback(OrthancPlugins::GetGlobalContext(), OnChangeCallback); OrthancPlugins::RegisterRestCallback("/wsi/libs/(.*)", true); - OrthancPlugins::RegisterRestCallback("/wsi/app/(viewer.html)", true); - OrthancPlugins::RegisterRestCallback("/wsi/app/(viewer.js)", true); + +#if ORTHANC_STANDALONE == 1 + OrthancPlugins::RegisterRestCallback("/wsi/app/(viewer.html)", true); + OrthancPlugins::RegisterRestCallback("/wsi/app/(viewer.js)", true); +#else + OrthancPlugins::RegisterRestCallback("/wsi/app/(viewer.html)", true); + OrthancPlugins::RegisterRestCallback("/wsi/app/(viewer.js)", true); +#endif + OrthancPlugins::RegisterRestCallback("/wsi/pyramids/([0-9a-f-]+)", true); OrthancPlugins::RegisterRestCallback("/wsi/tiles/([0-9a-f-]+)/([0-9-]+)/([0-9-]+)/([0-9-]+)", true); OrthancPlugins::RegisterRestCallback("/wsi/frames-pyramids/([0-9a-f-]+)/([0-9-]+)", true); @@ -598,12 +642,12 @@ if (serveMirador) { - OrthancPlugins::RegisterRestCallback("/wsi/app/(mirador.html)", true); + OrthancPlugins::RegisterRestCallback("/wsi/app/(mirador.html)", true); } if (serveOpenSeadragon) { - OrthancPlugins::RegisterRestCallback("/wsi/app/(openseadragon.html)", true); + OrthancPlugins::RegisterRestCallback("/wsi/app/(openseadragon.html)", true); } {