annotate Framework/Scene2DViewport/EditLineMeasureTracker.cpp @ 1203:f3bb9a6dd949 broker

locking abstraction in IViewport
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 29 Nov 2019 21:22:21 +0100
parents e713f1a99861
children 86a8266b8888
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
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
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
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
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
15 * Affero General Public License for more details.
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
16 *
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
19 **/
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 #include "EditLineMeasureTracker.h"
1020
ac88989817e3 TrackerCommand --> MeasureCommand + fuse against exception in MeasureTool dtor
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
22 #include "EditLineMeasureCommand.h"
ac88989817e3 TrackerCommand --> MeasureCommand + fuse against exception in MeasureTool dtor
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
23
1048
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
24 #include "../StoneException.h"
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
25
866
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
26
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
27 namespace OrthancStone
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 869
diff changeset
28 {
866
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
29 EditLineMeasureTracker::EditLineMeasureTracker(
1059
e713f1a99861 replacing MessageBroker by weak_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1048
diff changeset
30 boost::shared_ptr<MeasureTool> measureTool,
866
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
31 boost::weak_ptr<ViewportController> controllerW,
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 869
diff changeset
32 const PointerEvent& e)
866
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
33 : EditMeasureTracker(controllerW, e)
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 869
diff changeset
34 {
1203
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
35 ScenePoint2D scenePos = e.GetMainPosition();
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
36
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
37 {
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
38 boost::shared_ptr<ViewportController> controller = controllerW.lock();
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
39 if (controller)
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
40 {
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
41 std::auto_ptr<IViewport::ILock> lock(controller->GetViewport().Lock());
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
42 scenePos = e.GetMainPosition().Apply(lock->GetScene().GetCanvasToSceneTransform());
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
43 }
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
44 }
866
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45
1059
e713f1a99861 replacing MessageBroker by weak_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1048
diff changeset
46 modifiedZone_ = dynamic_cast<LineMeasureTool&>(*measureTool).LineHitTest(scenePos);
866
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
47
1059
e713f1a99861 replacing MessageBroker by weak_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1048
diff changeset
48 command_.reset(new EditLineMeasureCommand(measureTool, controllerW));
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 869
diff changeset
49 }
866
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 EditLineMeasureTracker::~EditLineMeasureTracker()
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 {
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 }
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
56 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
57 {
1203
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
58 boost::shared_ptr<ViewportController> controller = controllerW_.lock();
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
59 if (controller)
866
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 {
1203
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
61 std::auto_ptr<IViewport::ILock> lock(controller->GetViewport().Lock());
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
62 ScenePoint2D scenePos = e.GetMainPosition().Apply(
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
63 lock->GetScene().GetCanvasToSceneTransform());
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
64
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
65 ScenePoint2D delta = scenePos - GetOriginalClickPosition();
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
66
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
67 boost::shared_ptr<LineMeasureToolMemento> memento =
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
68 boost::dynamic_pointer_cast<LineMeasureToolMemento>(command_->mementoOriginal_);
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
69
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
70 ORTHANC_ASSERT(memento.get() != NULL);
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
71
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
72 switch (modifiedZone_)
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
73 {
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
74 case LineMeasureTool::LineHighlightArea_Start:
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
75 {
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
76 ScenePoint2D newStart = memento->start_ + delta;
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
77 GetCommand()->SetStart(newStart);
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
78 }
866
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
79 break;
1203
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
80 case LineMeasureTool::LineHighlightArea_End:
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
81 {
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
82 ScenePoint2D newEnd = memento->end_ + delta;
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
83 GetCommand()->SetEnd(newEnd);
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
84 }
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
85 break;
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
86 case LineMeasureTool::LineHighlightArea_Segment:
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
87 {
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
88 ScenePoint2D newStart = memento->start_ + delta;
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
89 ScenePoint2D newEnd = memento->end_ + delta;
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
90 GetCommand()->SetStart(newStart);
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
91 GetCommand()->SetEnd(newEnd);
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
92 }
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
93 break;
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
94 default:
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
95 LOG(WARNING) << "Warning: please retry the measuring tool editing operation!";
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
96 break;
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
97 }
866
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 }
1203
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1059
diff changeset
100
866
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
101 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
102 {
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
103 alive_ = false;
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
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
106 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
107 {
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
108 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
109 "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
110 }
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
111
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
112 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
113 {
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
114 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
115 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
116 return ret;
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
117 }
c71ef52602a0 Added the ability to edit existing measuring tools (demo not updated yet)
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
118
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 869
diff changeset
119 }