annotate Samples/Common/CreateAngleMeasureTracker.cpp @ 654:462a5074f914

Turned the scene into an observable to be able to dynamically react to scene to canvas transform changes --> now the handles and angle measure adornments are immune to zoom changes
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 14 May 2019 13:51:00 +0200
parents 1e9ed656318e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
1 /**
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
2 * Stone of Orthanc
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
6 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
10 * the License, or (at your option) any later version.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
11 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
15 * Affero General Public License for more details.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
16 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
19 **/
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
20
645
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
21 #include "CreateAngleMeasureTracker.h"
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
22 #include <Core/OrthancException.h>
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
23
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
24 using namespace Orthanc;
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
25
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
26 namespace OrthancStone
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
27 {
645
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
28 CreateAngleMeasureTracker::CreateAngleMeasureTracker(
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
29 MessageBroker& broker,
645
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
30 Scene2D& scene,
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
31 std::vector<TrackerCommandPtr>& undoStack,
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
32 std::vector<MeasureToolPtr>& measureTools,
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
33 const PointerEvent& e)
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
34 : CreateMeasureTracker(scene, undoStack, measureTools)
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
35 , state_(CreatingSide1)
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
36 {
645
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
37 command_.reset(
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
38 new CreateAngleMeasureCommand(
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
39 broker,
645
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
40 scene,
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
41 measureTools,
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
42 e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform())));
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
43 }
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
44
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
45 CreateAngleMeasureTracker::~CreateAngleMeasureTracker()
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
46 {
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
47 }
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
48
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
49 void CreateAngleMeasureTracker::PointerMove(const PointerEvent& event)
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
50 {
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
51 if (!active_)
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
52 {
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
53 throw OrthancException(ErrorCode_InternalError,
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
54 "Internal error: wrong state in CreateAngleMeasureTracker::"
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
55 "PointerMove: active_ == false");
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
56 }
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
57
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
58 ScenePoint2D scenePos = event.GetMainPosition().Apply(
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
59 scene_.GetCanvasToSceneTransform());
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
60
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
61 switch (state_)
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
62 {
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
63 case CreatingSide1:
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
64 GetCommand()->SetCenter(scenePos);
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
65 break;
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
66 case CreatingSide2:
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
67 GetCommand()->SetSide2End(scenePos);
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
68 break;
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
69 default:
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
70 throw OrthancException(ErrorCode_InternalError,
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
71 "Wrong state in CreateAngleMeasureTracker::"
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
72 "PointerMove: state_ invalid");
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
73 }
645
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
74 //LOG(TRACE) << "scenePos.GetX() = " << scenePos.GetX() << " " <<
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
75 // "scenePos.GetY() = " << scenePos.GetY();
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
76 }
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
77
645
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
78 void CreateAngleMeasureTracker::PointerUp(const PointerEvent& e)
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
79 {
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
80 // TODO: the current app does not prevent multiple PointerDown AND
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
81 // PointerUp to be sent to the tracker.
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
82 // Unless we augment the PointerEvent structure with the button index,
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
83 // we cannot really tell if this pointer up event matches the initial
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
84 // pointer down event. Let's make it simple for now.
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
85
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
86 switch (state_)
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
87 {
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
88 case CreatingSide1:
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
89 state_ = CreatingSide2;
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
90 break;
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
91 case CreatingSide2:
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
92 throw OrthancException(ErrorCode_InternalError,
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
93 "Wrong state in CreateAngleMeasureTracker::"
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
94 "PointerUp: state_ == CreatingSide2 ; this should not happen");
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
95 break;
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
96 default:
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
97 throw OrthancException(ErrorCode_InternalError,
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
98 "Wrong state in CreateAngleMeasureTracker::"
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
99 "PointerMove: state_ invalid");
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
100 }
645
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
101 }
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
102
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
103 void CreateAngleMeasureTracker::PointerDown(const PointerEvent& e)
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
104 {
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
105 switch (state_)
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
106 {
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
107 case CreatingSide1:
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
108 throw OrthancException(ErrorCode_InternalError,
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
109 "Wrong state in CreateAngleMeasureTracker::"
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
110 "PointerDown: state_ == CreatingSide1 ; this should not happen");
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
111 break;
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
112 case CreatingSide2:
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
113 // we are done
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
114 active_ = false;
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
115 break;
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
116 default:
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
117 throw OrthancException(ErrorCode_InternalError,
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
118 "Wrong state in CreateAngleMeasureTracker::"
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
119 "PointerMove: state_ invalid");
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 645
diff changeset
120 }
645
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
121 }
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
122
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
123 CreateAngleMeasureCommandPtr CreateAngleMeasureTracker::GetCommand()
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
124 {
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
125 return boost::dynamic_pointer_cast<CreateAngleMeasureCommand>(command_);
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
126 }
1e9ed656318e Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
127
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128 }