Mercurial > hg > orthanc-stone
comparison Framework/Scene2DViewport/ViewportController.cpp @ 700:059e1fd05fd6 refactor-viewport-controller
Introduced the ViewportController that sits between the application and the
Scene2D to handle the trackers and measuring tools. This is a work in progress.
The Scene2D is no longer an observable. Message sending is managed by the
ViewportController.
Move some refs to shared and weak to prevent lifetime issues.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Sun, 19 May 2019 16:26:17 +0200 |
parents | 8b6adfb62a2f |
children | af0aa0c149fa |
comparison
equal
deleted
inserted
replaced
699:5c551f078c18 | 700:059e1fd05fd6 |
---|---|
20 | 20 |
21 #include "ViewportController.h" | 21 #include "ViewportController.h" |
22 | 22 |
23 #include <Framework/StoneException.h> | 23 #include <Framework/StoneException.h> |
24 | 24 |
25 #include <boost/make_shared.hpp> | |
26 | |
25 using namespace Orthanc; | 27 using namespace Orthanc; |
26 | 28 |
27 namespace OrthancStone | 29 namespace OrthancStone |
28 { | 30 { |
29 | |
30 ViewportController::ViewportController(MessageBroker& broker) | 31 ViewportController::ViewportController(MessageBroker& broker) |
31 : broker_(broker) | 32 : IObservable(broker) |
32 { | 33 { |
33 | 34 scene_ = boost::make_shared<Scene2D>(); |
34 } | 35 } |
35 | 36 |
36 Scene2DPtr ViewportController::GetScene() | 37 Scene2DPtr ViewportController::GetScene() |
37 { | 38 { |
38 Scene2DPtr scene = scene_.lock(); | 39 return scene_; |
39 if (!scene) | |
40 throw OrthancException(ErrorCode_InternalError, "Using dead object!"); | |
41 return scene; | |
42 } | 40 } |
43 | 41 |
44 bool ViewportController::HandlePointerEvent(PointerEvent e) | 42 bool ViewportController::HandlePointerEvent(PointerEvent e) |
45 { | 43 { |
46 throw StoneException(ErrorCode_NotImplemented); | 44 throw StoneException(ErrorCode_NotImplemented); |
47 } | 45 } |
46 | |
47 const OrthancStone::AffineTransform2D& ViewportController::GetCanvasToSceneTransform() const | |
48 { | |
49 return scene_->GetCanvasToSceneTransform(); | |
50 } | |
51 | |
52 const OrthancStone::AffineTransform2D& ViewportController::GetSceneToCanvasTransform() const | |
53 { | |
54 return scene_->GetSceneToCanvasTransform(); | |
55 } | |
56 | |
57 void ViewportController::SetSceneToCanvasTransform( | |
58 const AffineTransform2D& transform) | |
59 { | |
60 scene_->SetSceneToCanvasTransform(transform); | |
61 BroadcastMessage(SceneTransformChanged(*this)); | |
62 } | |
63 | |
48 } | 64 } |
49 | 65 |