comparison Framework/Scene2DViewport/MeasureTrackers.cpp @ 1305:a5326ce4f24b broker

Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 04 Mar 2020 09:45:38 +0100
parents 7ec8fea061b9
children ab81ee8fce1f
comparison
equal deleted inserted replaced
1304:b7fa67bf87fa 1305:a5326ce4f24b
22 #include <Core/OrthancException.h> 22 #include <Core/OrthancException.h>
23 23
24 namespace OrthancStone 24 namespace OrthancStone
25 { 25 {
26 26
27 CreateMeasureTracker::CreateMeasureTracker(boost::weak_ptr<ViewportController> controllerW) 27 CreateMeasureTracker::CreateMeasureTracker(IViewport& viewport)
28 : controllerW_(controllerW) 28 : viewport_(viewport)
29 , alive_(true) 29 , alive_(true)
30 , commitResult_(true) 30 , commitResult_(true)
31 { 31 {
32 } 32 }
33 33
45 CreateMeasureTracker::~CreateMeasureTracker() 45 CreateMeasureTracker::~CreateMeasureTracker()
46 { 46 {
47 // if the tracker completes successfully, we add the command 47 // if the tracker completes successfully, we add the command
48 // to the undo stack 48 // to the undo stack
49 // otherwise, we simply undo it 49 // otherwise, we simply undo it
50
51 std::unique_ptr<IViewport::ILock> lock(viewport_.Lock());
52 ViewportController& controller = lock->GetController();
53
50 if (commitResult_) 54 if (commitResult_)
51 controllerW_.lock()->PushCommand(command_); 55 lock->GetController().PushCommand(command_);
52 else 56 else
53 command_->Undo(); 57 command_->Undo();
58
59 lock->Invalidate();
54 } 60 }
55 61
56 EditMeasureTracker::EditMeasureTracker(boost::weak_ptr<ViewportController> controllerW, const PointerEvent& e) 62 EditMeasureTracker::EditMeasureTracker(IViewport& viewport, const PointerEvent& e)
57 : controllerW_(controllerW) 63 : viewport_(viewport)
58 , alive_(true) 64 , alive_(true)
59 , commitResult_(true) 65 , commitResult_(true)
60 { 66 {
61 boost::shared_ptr<ViewportController> controller = controllerW.lock(); 67 std::unique_ptr<IViewport::ILock> lock(viewport_.Lock());
68 ViewportController& controller = lock->GetController();
62 69
63 if (controller) 70 originalClickPosition_ = e.GetMainPosition().Apply(
64 { 71 controller.GetScene().GetCanvasToSceneTransform());
65 originalClickPosition_ = e.GetMainPosition().Apply(controller->GetScene().GetCanvasToSceneTransform());
66 }
67 } 72 }
68 73
69 void EditMeasureTracker::Cancel() 74 void EditMeasureTracker::Cancel()
70 { 75 {
71 commitResult_ = false; 76 commitResult_ = false;
80 EditMeasureTracker::~EditMeasureTracker() 85 EditMeasureTracker::~EditMeasureTracker()
81 { 86 {
82 // if the tracker completes successfully, we add the command 87 // if the tracker completes successfully, we add the command
83 // to the undo stack 88 // to the undo stack
84 // otherwise, we simply undo it 89 // otherwise, we simply undo it
90
91 std::unique_ptr<IViewport::ILock> lock(viewport_.Lock());
92 ViewportController& controller = lock->GetController();
93
85 if (commitResult_) 94 if (commitResult_)
86 controllerW_.lock()->PushCommand(command_); 95 lock->GetController().PushCommand(command_);
87 else 96 else
88 command_->Undo(); 97 command_->Undo();
98
99 lock->Invalidate();
89 } 100 }
90 } 101 }
91 102
92 103