Mercurial > hg > orthanc-stone
changeset 1579:c476b0d5e59c
skeleton for cross-hair tool
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 30 Sep 2020 19:09:03 +0200 |
parents | 1f812f4c95be |
children | c6b29bf58914 |
files | Applications/StoneWebViewer/WebApplication/index.html Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp OrthancStone/Sources/StoneEnumerations.h OrthancStone/Sources/Viewport/DefaultViewportInteractor.cpp |
diffstat | 4 files changed, 117 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebApplication/index.html Thu Sep 24 17:20:36 2020 +0200 +++ b/Applications/StoneWebViewer/WebApplication/index.html Wed Sep 30 19:09:03 2020 +0200 @@ -302,24 +302,31 @@ <div class="inline-object"> <button class="wvButton" data-toggle="tooltip" data-title="Combined tool" - @click="SetMouseButtonActions(stone.MouseAction.GRAYSCALE_WINDOWING, stone.MouseAction.PAN, stone.MouseAction.ZOOM)"> + @click="SetMouseButtonActions(stone.WebViewerAction.GRAYSCALE_WINDOWING, stone.WebViewerAction.PAN, stone.WebViewerAction.ZOOM)"> <i class="far fa-hand-point-up"></i> </button> </div> <div class="inline-object"> <button class="wvButton" data-toggle="tooltip" data-title="Zoom" - @click="SetMouseButtonActions(stone.MouseAction.ZOOM, stone.MouseAction.ZOOM, stone.MouseAction.ZOOM)"> + @click="SetMouseButtonActions(stone.WebViewerAction.ZOOM, stone.WebViewerAction.ZOOM, stone.WebViewerAction.ZOOM)"> <i class="fas fa-search"></i> </button> </div> <div class="inline-object"> <button class="wvButton" data-toggle="tooltip" data-title="Pan" - @click="SetMouseButtonActions(stone.MouseAction.PAN, stone.MouseAction.PAN, stone.MouseAction.PAN)"> + @click="SetMouseButtonActions(stone.WebViewerAction.PAN, stone.WebViewerAction.PAN, stone.WebViewerAction.PAN)"> <i class="fas fa-arrows-alt"></i> </button> </div> + <div class="inline-object"> + <button class="wvButton" + data-toggle="tooltip" data-title="3D cross-hair" + @click="SetMouseButtonActions(stone.WebViewerAction.CROSSHAIR, stone.WebViewerAction.PAN, stone.WebViewerAction.ZOOM)"> + <i class="fas fa-crosshairs"></i> + </button> + </div> </div> </div> </div>
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp Thu Sep 24 17:20:36 2020 +0200 +++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp Wed Sep 30 19:09:03 2020 +0200 @@ -105,16 +105,43 @@ }; -enum EMSCRIPTEN_KEEPALIVE MouseAction +enum EMSCRIPTEN_KEEPALIVE WebViewerAction { - MouseAction_GrayscaleWindowing, - MouseAction_Zoom, - MouseAction_Pan, - MouseAction_Rotate + WebViewerAction_GrayscaleWindowing, + WebViewerAction_Zoom, + WebViewerAction_Pan, + WebViewerAction_Rotate, + WebViewerAction_Crosshair }; +static OrthancStone::MouseAction ConvertWebViewerAction(int action) +{ + switch (action) + { + case WebViewerAction_GrayscaleWindowing: + return OrthancStone::MouseAction_GrayscaleWindowing; + + case WebViewerAction_Zoom: + return OrthancStone::MouseAction_Zoom; + + case WebViewerAction_Pan: + return OrthancStone::MouseAction_Pan; + + case WebViewerAction_Rotate: + return OrthancStone::MouseAction_Rotate; + + case WebViewerAction_Crosshair: + return OrthancStone::MouseAction_None; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } +} + + + static const int PRIORITY_HIGH = -100; static const int PRIORITY_LOW = 100; static const int PRIORITY_NORMAL = 0; @@ -1892,19 +1919,73 @@ } } - void SetMouseButtonActions(OrthancStone::MouseAction leftAction, - OrthancStone::MouseAction middleAction, - OrthancStone::MouseAction rightAction) + + + class Interactor : public OrthancStone::DefaultViewportInteractor { - std::unique_ptr<OrthancStone::DefaultViewportInteractor> interactor( - new OrthancStone::DefaultViewportInteractor); + private: + WebViewerAction leftAction_; + WebViewerAction middleAction_; + WebViewerAction rightAction_; + + bool IsAction(const OrthancStone::PointerEvent& event, + WebViewerAction action) + { + switch (event.GetMouseButton()) + { + case OrthancStone::MouseButton_Left: + return (leftAction_ == action); + + case OrthancStone::MouseButton_Middle: + return (middleAction_ == action); + + case OrthancStone::MouseButton_Right: + return (rightAction_ == action); + + default: + return false; + } + } - interactor->SetLeftButtonAction(leftAction); - interactor->SetMiddleButtonAction(middleAction); - interactor->SetRightButtonAction(rightAction); + public: + Interactor(WebViewerAction leftAction, + WebViewerAction middleAction, + WebViewerAction rightAction) : + leftAction_(leftAction), + middleAction_(middleAction), + rightAction_(rightAction) + { + SetLeftButtonAction(ConvertWebViewerAction(leftAction)); + SetMiddleButtonAction(ConvertWebViewerAction(middleAction)); + SetRightButtonAction(ConvertWebViewerAction(rightAction)); + } + virtual OrthancStone::IFlexiblePointerTracker* CreateTracker( + boost::shared_ptr<OrthancStone::IViewport> viewport, + const OrthancStone::PointerEvent& event, + unsigned int viewportWidth, + unsigned int viewportHeight) ORTHANC_OVERRIDE + { + if (IsAction(event, WebViewerAction_Crosshair)) + { + printf("CROSS-HAIR!\n"); + return NULL; + } + else + { + return DefaultViewportInteractor::CreateTracker( + viewport, event, viewportWidth, viewportHeight); + } + } + }; + + + void SetMouseButtonActions(WebViewerAction leftAction, + WebViewerAction middleAction, + WebViewerAction rightAction) + { assert(viewport_ != NULL); - viewport_->AcquireInteractor(interactor.release()); + viewport_->AcquireInteractor(new Interactor(leftAction, middleAction, rightAction)); } void FitForPrint() @@ -2019,9 +2100,9 @@ static boost::shared_ptr<OrthancStone::WebAssemblyLoadersContext> context_; static std::string stringBuffer_; static bool softwareRendering_ = false; -static OrthancStone::MouseAction leftButtonAction_ = OrthancStone::MouseAction_GrayscaleWindowing; -static OrthancStone::MouseAction middleButtonAction_ = OrthancStone::MouseAction_Pan; -static OrthancStone::MouseAction rightButtonAction_ = OrthancStone::MouseAction_Zoom; +static WebViewerAction leftButtonAction_ = WebViewerAction_GrayscaleWindowing; +static WebViewerAction middleButtonAction_ = WebViewerAction_Pan; +static WebViewerAction rightButtonAction_ = WebViewerAction_Zoom; static void FormatTags(std::string& target, @@ -2079,30 +2160,6 @@ } - -static OrthancStone::MouseAction ConvertMouseAction(int action) -{ - switch (action) - { - case MouseAction_GrayscaleWindowing: - return OrthancStone::MouseAction_GrayscaleWindowing; - - case MouseAction_Zoom: - return OrthancStone::MouseAction_Zoom; - - case MouseAction_Pan: - return OrthancStone::MouseAction_Pan; - - case MouseAction_Rotate: - return OrthancStone::MouseAction_Rotate; - - default: - throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); - } -} - - - extern "C" { int main(int argc, char const *argv[]) @@ -2451,9 +2508,9 @@ { try { - leftButtonAction_ = ConvertMouseAction(leftAction); - middleButtonAction_ = ConvertMouseAction(middleAction); - rightButtonAction_ = ConvertMouseAction(rightAction); + leftButtonAction_ = static_cast<WebViewerAction>(leftAction); + middleButtonAction_ = static_cast<WebViewerAction>(middleAction); + rightButtonAction_ = static_cast<WebViewerAction>(rightAction); for (Viewports::iterator it = allViewports_.begin(); it != allViewports_.end(); ++it) {
--- a/OrthancStone/Sources/StoneEnumerations.h Thu Sep 24 17:20:36 2020 +0200 +++ b/OrthancStone/Sources/StoneEnumerations.h Wed Sep 30 19:09:03 2020 +0200 @@ -137,7 +137,8 @@ MouseAction_Pan, MouseAction_Zoom, MouseAction_Rotate, - MouseAction_GrayscaleWindowing + MouseAction_GrayscaleWindowing, + MouseAction_None }; SopClassUid StringToSopClassUid(const std::string& source);
--- a/OrthancStone/Sources/Viewport/DefaultViewportInteractor.cpp Thu Sep 24 17:20:36 2020 +0200 +++ b/OrthancStone/Sources/Viewport/DefaultViewportInteractor.cpp Wed Sep 30 19:09:03 2020 +0200 @@ -38,6 +38,9 @@ { switch (action) { + case MouseAction_None: + return NULL; + case MouseAction_Rotate: return new RotateSceneTracker(viewport, event); @@ -50,7 +53,7 @@ case MouseAction_Zoom: return new ZoomSceneTracker(viewport, event, viewportHeight); - + default: throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); }