Mercurial > hg > orthanc-stone
annotate Samples/Common/CreateAngleMeasureTracker.cpp @ 693:9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 17 May 2019 08:49:55 +0200 |
parents | 462a5074f914 |
children |
rev | line source |
---|---|
644 | 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-2019 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 | |
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 | 26 namespace OrthancStone |
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 | 128 } |