Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Scene2DViewport/MeasureTrackers.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 #include <OrthancException.h> | 23 #include <OrthancException.h> |
24 | 24 |
25 namespace OrthancStone | 25 namespace OrthancStone |
26 { | 26 { |
27 | 27 |
28 CreateMeasureTracker::CreateMeasureTracker(boost::shared_ptr<IViewport> viewport) : | 28 CreateMeasureTracker::CreateMeasureTracker(boost::weak_ptr<IViewport> viewport) : |
29 commitResult_(true), | 29 commitResult_(true), |
30 viewport_(viewport), | 30 viewport_(viewport), |
31 alive_(true) | 31 alive_(true) |
32 { | 32 { |
33 } | |
34 | |
35 IViewport::ILock* CreateMeasureTracker::GetViewportLock() | |
36 { | |
37 boost::shared_ptr<IViewport> viewport = viewport_.lock(); | |
38 if (viewport) | |
39 return viewport->Lock(); | |
40 else | |
41 return nullptr; | |
33 } | 42 } |
34 | 43 |
35 void CreateMeasureTracker::Cancel() | 44 void CreateMeasureTracker::Cancel() |
36 { | 45 { |
37 commitResult_ = false; | 46 commitResult_ = false; |
47 { | 56 { |
48 // if the tracker completes successfully, we add the command | 57 // if the tracker completes successfully, we add the command |
49 // to the undo stack | 58 // to the undo stack |
50 // otherwise, we simply undo it | 59 // otherwise, we simply undo it |
51 | 60 |
52 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | 61 std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); |
53 | 62 |
54 if (commitResult_) | 63 if (commitResult_) |
55 lock->GetController().PushCommand(command_); | 64 lock->GetController().PushCommand(command_); |
56 else | 65 else |
57 command_->Undo(); | 66 command_->Undo(); |
58 | 67 |
59 lock->Invalidate(); | 68 lock->Invalidate(); |
60 } | 69 } |
61 | 70 |
62 EditMeasureTracker::EditMeasureTracker(boost::shared_ptr<IViewport> viewport, | 71 EditMeasureTracker::EditMeasureTracker(boost::weak_ptr<IViewport> viewport, |
63 const PointerEvent& e) : | 72 const PointerEvent& e) : |
64 commitResult_(true), | 73 commitResult_(true), |
65 viewport_(viewport), | 74 viewport_(viewport), |
66 alive_(true) | 75 alive_(true) |
67 { | 76 { |
68 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | 77 std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); |
69 | 78 |
70 originalClickPosition_ = e.GetMainPosition().Apply( | 79 originalClickPosition_ = e.GetMainPosition().Apply( |
71 lock->GetController().GetScene().GetCanvasToSceneTransform()); | 80 lock->GetController().GetScene().GetCanvasToSceneTransform()); |
81 } | |
82 | |
83 IViewport::ILock* EditMeasureTracker::GetViewportLock() | |
84 { | |
85 boost::shared_ptr<IViewport> viewport = viewport_.lock(); | |
86 if (viewport) | |
87 return viewport->Lock(); | |
88 else | |
89 return nullptr; | |
72 } | 90 } |
73 | 91 |
74 void EditMeasureTracker::Cancel() | 92 void EditMeasureTracker::Cancel() |
75 { | 93 { |
76 commitResult_ = false; | 94 commitResult_ = false; |
86 { | 104 { |
87 // if the tracker completes successfully, we add the command | 105 // if the tracker completes successfully, we add the command |
88 // to the undo stack | 106 // to the undo stack |
89 // otherwise, we simply undo it | 107 // otherwise, we simply undo it |
90 | 108 |
91 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | 109 std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); |
92 | 110 |
93 if (commitResult_) | 111 if (commitResult_) |
94 lock->GetController().PushCommand(command_); | 112 lock->GetController().PushCommand(command_); |
95 else | 113 else |
96 command_->Undo(); | 114 command_->Undo(); |