Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2DViewport/EditLineMeasureTracker.cpp @ 1739:9ac2a65d4172
upgrade to year 2021
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 06 Jan 2021 17:50:00 +0100 |
parents | 874e178f34e9 |
children | 9b650ab68d4c |
rev | line source |
---|---|
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
1 /** |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
2 * Stone of Orthanc |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1606
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
6 * |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
11 * |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
15 * Lesser General Public License for more details. |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
20 **/ |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
21 |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
22 #include "EditLineMeasureTracker.h" |
1020
ac88989817e3
TrackerCommand --> MeasureCommand + fuse against exception in MeasureTool dtor
Benjamin Golinvaux <bgo@osimis.io>
parents:
891
diff
changeset
|
23 #include "EditLineMeasureCommand.h" |
ac88989817e3
TrackerCommand --> MeasureCommand + fuse against exception in MeasureTool dtor
Benjamin Golinvaux <bgo@osimis.io>
parents:
891
diff
changeset
|
24 |
1048
f6be9412e42a
cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
25 #include "../StoneException.h" |
f6be9412e42a
cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
26 |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
27 |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
28 namespace OrthancStone |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
869
diff
changeset
|
29 { |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
30 EditLineMeasureTracker::EditLineMeasureTracker( |
1059
e713f1a99861
replacing MessageBroker by weak_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1048
diff
changeset
|
31 boost::shared_ptr<MeasureTool> measureTool, |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
32 boost::weak_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
|
33 const PointerEvent& e) |
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
|
34 : EditMeasureTracker(viewport, e) |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
869
diff
changeset
|
35 { |
1571 | 36 ScenePoint2D scenePos; |
37 | |
1203
f3bb9a6dd949
locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1059
diff
changeset
|
38 { |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
39 std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); |
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
|
40 Scene2D& scene = lock->GetController().GetScene(); |
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
|
41 scenePos = e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform()); |
1203
f3bb9a6dd949
locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1059
diff
changeset
|
42 } |
1571 | 43 |
1059
e713f1a99861
replacing MessageBroker by weak_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1048
diff
changeset
|
44 modifiedZone_ = dynamic_cast<LineMeasureTool&>(*measureTool).LineHitTest(scenePos); |
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
|
45 command_.reset(new EditLineMeasureCommand(measureTool, viewport)); |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
869
diff
changeset
|
46 } |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
47 |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
48 void EditLineMeasureTracker::PointerMove(const PointerEvent& e) |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
49 { |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
50 std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); |
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
|
51 ViewportController& controller = lock->GetController(); |
1571 | 52 const Scene2D& scene = controller.GetScene(); |
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
|
53 |
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
|
54 ScenePoint2D scenePos = 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
|
55 scene.GetCanvasToSceneTransform()); |
1203
f3bb9a6dd949
locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1059
diff
changeset
|
56 |
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
|
57 ScenePoint2D delta = scenePos - GetOriginalClickPosition(); |
1203
f3bb9a6dd949
locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1059
diff
changeset
|
58 |
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
|
59 boost::shared_ptr<LineMeasureToolMemento> memento = |
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
|
60 boost::dynamic_pointer_cast<LineMeasureToolMemento>(command_->mementoOriginal_); |
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
|
61 |
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
|
62 ORTHANC_ASSERT(memento.get() != NULL); |
1203
f3bb9a6dd949
locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1059
diff
changeset
|
63 |
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
|
64 switch (modifiedZone_) |
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
|
65 { |
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
|
66 case LineMeasureTool::LineHighlightArea_Start: |
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
|
67 { |
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 ScenePoint2D newStart = memento->start_ + delta; |
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
|
69 GetCommand()->SetStart(newStart); |
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 } |
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 break; |
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
|
72 case LineMeasureTool::LineHighlightArea_End: |
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
|
73 { |
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
|
74 ScenePoint2D newEnd = memento->end_ + delta; |
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
|
75 GetCommand()->SetEnd(newEnd); |
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
|
76 } |
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
|
77 break; |
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
|
78 case LineMeasureTool::LineHighlightArea_Segment: |
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
|
79 { |
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
|
80 ScenePoint2D newStart = memento->start_ + delta; |
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
|
81 ScenePoint2D newEnd = memento->end_ + delta; |
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
|
82 GetCommand()->SetStart(newStart); |
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
|
83 GetCommand()->SetEnd(newEnd); |
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
|
84 } |
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
|
85 break; |
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
|
86 default: |
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
|
87 LOG(WARNING) << "Warning: please retry the measuring tool editing operation!"; |
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
|
88 break; |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
89 } |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
90 } |
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
|
91 |
866
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
92 void EditLineMeasureTracker::PointerUp(const PointerEvent& e) |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
93 { |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
94 alive_ = false; |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
95 } |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
96 |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
97 void EditLineMeasureTracker::PointerDown(const PointerEvent& e) |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
98 { |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
99 LOG(WARNING) << "Additional touches (fingers, pen, mouse buttons...) " |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
100 "are ignored when the edit line tracker is active"; |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
101 } |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
102 |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
103 boost::shared_ptr<EditLineMeasureCommand> EditLineMeasureTracker::GetCommand() |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
104 { |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
105 boost::shared_ptr<EditLineMeasureCommand> ret = boost::dynamic_pointer_cast<EditLineMeasureCommand>(command_); |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
106 ORTHANC_ASSERT(ret.get() != NULL, "Internal error in EditLineMeasureTracker::GetCommand()"); |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
107 return ret; |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
108 } |
c71ef52602a0
Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
109 |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
869
diff
changeset
|
110 } |