comparison OrthancStone/Sources/Scene2DViewport/MeasureTrackers.cpp @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Scene2DViewport/MeasureTrackers.cpp@1e381f2596d3
children 85e117739eca
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21 #include "MeasureTrackers.h"
22 #include <OrthancException.h>
23
24 namespace OrthancStone
25 {
26
27 CreateMeasureTracker::CreateMeasureTracker(boost::shared_ptr<IViewport> viewport)
28 : viewport_(viewport)
29 , alive_(true)
30 , commitResult_(true)
31 {
32 }
33
34 void CreateMeasureTracker::Cancel()
35 {
36 commitResult_ = false;
37 alive_ = false;
38 }
39
40 bool CreateMeasureTracker::IsAlive() const
41 {
42 return alive_;
43 }
44
45 CreateMeasureTracker::~CreateMeasureTracker()
46 {
47 // if the tracker completes successfully, we add the command
48 // to the undo stack
49 // otherwise, we simply undo it
50
51 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
52
53 if (commitResult_)
54 lock->GetController().PushCommand(command_);
55 else
56 command_->Undo();
57
58 lock->Invalidate();
59 }
60
61 EditMeasureTracker::EditMeasureTracker(boost::shared_ptr<IViewport> viewport, const PointerEvent& e)
62 : viewport_(viewport)
63 , alive_(true)
64 , commitResult_(true)
65 {
66 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
67
68 originalClickPosition_ = e.GetMainPosition().Apply(
69 lock->GetController().GetScene().GetCanvasToSceneTransform());
70 }
71
72 void EditMeasureTracker::Cancel()
73 {
74 commitResult_ = false;
75 alive_ = false;
76 }
77
78 bool EditMeasureTracker::IsAlive() const
79 {
80 return alive_;
81 }
82
83 EditMeasureTracker::~EditMeasureTracker()
84 {
85 // if the tracker completes successfully, we add the command
86 // to the undo stack
87 // otherwise, we simply undo it
88
89 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
90
91 if (commitResult_)
92 lock->GetController().PushCommand(command_);
93 else
94 command_->Undo();
95
96 lock->Invalidate();
97 }
98 }
99
100