Mercurial > hg > orthanc-stone
annotate Framework/Scene2DViewport/MeasureTrackers.cpp @ 1418:4e7751a4b603 loader-injection-feature
Added a test for loader injection (basic "no regression" test). DISABLED_ because it requires a running Orthanc with a well-defined structure set instance.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 11 May 2020 17:41:50 +0200 |
parents | ab81ee8fce1f |
children | 30deba7bc8e2 |
rev | line source |
---|---|
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
1 /** |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
2 * Stone of Orthanc |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
891
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
6 * |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
11 * |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
16 * |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
19 **/ |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
20 |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
21 #include "MeasureTrackers.h" |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
22 #include <Core/OrthancException.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
23 |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
24 namespace OrthancStone |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
25 { |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
26 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1305
diff
changeset
|
27 CreateMeasureTracker::CreateMeasureTracker(boost::shared_ptr<IViewport> viewport) |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
28 : viewport_(viewport) |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
698
diff
changeset
|
29 , alive_(true) |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
30 , commitResult_(true) |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
31 { |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
32 } |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
33 |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
34 void CreateMeasureTracker::Cancel() |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
35 { |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
36 commitResult_ = false; |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
698
diff
changeset
|
37 alive_ = false; |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
38 } |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
39 |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
698
diff
changeset
|
40 bool CreateMeasureTracker::IsAlive() const |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
41 { |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
698
diff
changeset
|
42 return alive_; |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
43 } |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
44 |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
45 CreateMeasureTracker::~CreateMeasureTracker() |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
46 { |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
47 // if the tracker completes successfully, we add the command |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
48 // to the undo stack |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
49 // otherwise, we simply undo it |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
50 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1305
diff
changeset
|
51 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
52 ViewportController& controller = lock->GetController(); |
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
53 |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
54 if (commitResult_) |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
55 lock->GetController().PushCommand(command_); |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
56 else |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
57 command_->Undo(); |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
58 |
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
59 lock->Invalidate(); |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
60 } |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
698
diff
changeset
|
61 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1305
diff
changeset
|
62 EditMeasureTracker::EditMeasureTracker(boost::shared_ptr<IViewport> viewport, const PointerEvent& e) |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
63 : viewport_(viewport) |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
64 , alive_(true) |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
65 , commitResult_(true) |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
66 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1305
diff
changeset
|
67 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
68 ViewportController& controller = lock->GetController(); |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
69 |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
70 originalClickPosition_ = e.GetMainPosition().Apply( |
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
71 controller.GetScene().GetCanvasToSceneTransform()); |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
72 } |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
73 |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
74 void EditMeasureTracker::Cancel() |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
75 { |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
76 commitResult_ = false; |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
77 alive_ = false; |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
78 } |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
79 |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
80 bool EditMeasureTracker::IsAlive() const |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
81 { |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
82 return alive_; |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
83 } |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
84 |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
85 EditMeasureTracker::~EditMeasureTracker() |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
86 { |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
87 // if the tracker completes successfully, we add the command |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
88 // to the undo stack |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
89 // otherwise, we simply undo it |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
90 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1305
diff
changeset
|
91 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
92 ViewportController& controller = lock->GetController(); |
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
93 |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
94 if (commitResult_) |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
95 lock->GetController().PushCommand(command_); |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
96 else |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
97 command_->Undo(); |
1305
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
98 |
a5326ce4f24b
Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
Benjamin Golinvaux <bgo@osimis.io>
parents:
1279
diff
changeset
|
99 lock->Invalidate(); |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
100 } |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
101 } |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
102 |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
103 |