Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Scene2DViewport/MeasureTool.cpp @ 1606:874e178f34e9
- ViewportController now has weak ptr to Viewport
- Measuring tools + related commands and all trackers now store only a weak_ptr to the Viewport and lock() on demand for usage
- LayerHolder and FixedPoint aligner store only a weak_ptr to the Viewport, too
- Fixed float/double warning in GrayscaleWindowingSceneTracker
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 28 Oct 2020 20:14:34 +0100 |
parents | 8563ea5d8ae4 |
children | 646e581e115b |
comparison
equal
deleted
inserted
replaced
1605:b3c439d96d3e | 1606:874e178f34e9 |
---|---|
23 | 23 |
24 #include <Logging.h> | 24 #include <Logging.h> |
25 #include <Enumerations.h> | 25 #include <Enumerations.h> |
26 #include <OrthancException.h> | 26 #include <OrthancException.h> |
27 | 27 |
28 #include <boost/shared_ptr.hpp> | |
28 #include <boost/math/constants/constants.hpp> | 29 #include <boost/math/constants/constants.hpp> |
29 | 30 |
30 #include "../Viewport/IViewport.h" | 31 #include "../Viewport/IViewport.h" |
31 | 32 |
32 namespace OrthancStone | 33 namespace OrthancStone |
46 bool MeasureTool::IsEnabled() const | 47 bool MeasureTool::IsEnabled() const |
47 { | 48 { |
48 return enabled_; | 49 return enabled_; |
49 } | 50 } |
50 | 51 |
51 MeasureTool::MeasureTool(boost::shared_ptr<IViewport> viewport) : | 52 IViewport::ILock* MeasureTool::GetViewportLock() |
53 { | |
54 boost::shared_ptr<IViewport> viewport = viewport_.lock(); | |
55 if(viewport) | |
56 return viewport->Lock(); | |
57 else | |
58 return nullptr; | |
59 } | |
60 | |
61 IViewport::ILock* MeasureTool::GetViewportLock() const | |
62 { | |
63 boost::shared_ptr<IViewport> viewport = viewport_.lock(); | |
64 if (viewport) | |
65 return viewport->Lock(); | |
66 else | |
67 return nullptr; | |
68 } | |
69 | |
70 MeasureTool::MeasureTool(boost::weak_ptr<IViewport> viewport) : | |
52 enabled_(true), | 71 enabled_(true), |
53 viewport_(viewport) | 72 viewport_(viewport) |
54 { | 73 { |
55 } | 74 } |
56 | 75 |
57 void MeasureTool::PostConstructor() | 76 void MeasureTool::PostConstructor() |
58 { | 77 { |
59 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | 78 std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); |
60 ViewportController& controller = lock->GetController(); | 79 ViewportController& controller = lock->GetController(); |
61 | 80 |
62 Register<ViewportController::SceneTransformChanged>( | 81 Register<ViewportController::SceneTransformChanged>( |
63 controller, | 82 controller, |
64 &MeasureTool::OnSceneTransformChanged); | 83 &MeasureTool::OnSceneTransformChanged); |