Mercurial > hg > orthanc-stone
comparison Framework/Scene2DViewport/CreateAngleMeasureTracker.cpp @ 728:8190213e2279 am-dev
Merged default into am-dev
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 21 May 2019 13:25:58 +0200 |
parents | 28b9e3a54200 |
children | 8e31b174ab26 |
comparison
equal
deleted
inserted
replaced
690:f185cfcb72a0 | 728:8190213e2279 |
---|---|
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 | |
21 #include "CreateAngleMeasureTracker.h" | |
22 #include <Core/OrthancException.h> | |
23 | |
24 using namespace Orthanc; | |
25 | |
26 namespace OrthancStone | |
27 { | |
28 CreateAngleMeasureTracker::CreateAngleMeasureTracker( | |
29 MessageBroker& broker, | |
30 ViewportControllerWPtr controllerW, | |
31 const PointerEvent& e) | |
32 : CreateMeasureTracker(controllerW) | |
33 , state_(CreatingSide1) | |
34 { | |
35 command_.reset( | |
36 new CreateAngleMeasureCommand( | |
37 broker, | |
38 controllerW, | |
39 e.GetMainPosition().Apply(GetScene()->GetCanvasToSceneTransform()))); | |
40 } | |
41 | |
42 CreateAngleMeasureTracker::~CreateAngleMeasureTracker() | |
43 { | |
44 } | |
45 | |
46 void CreateAngleMeasureTracker::PointerMove(const PointerEvent& event) | |
47 { | |
48 assert(GetScene()); | |
49 | |
50 if (!alive_) | |
51 { | |
52 throw OrthancException(ErrorCode_InternalError, | |
53 "Internal error: wrong state in CreateAngleMeasureTracker::" | |
54 "PointerMove: active_ == false"); | |
55 } | |
56 | |
57 ScenePoint2D scenePos = event.GetMainPosition().Apply( | |
58 GetScene()->GetCanvasToSceneTransform()); | |
59 | |
60 switch (state_) | |
61 { | |
62 case CreatingSide1: | |
63 GetCommand()->SetCenter(scenePos); | |
64 break; | |
65 case CreatingSide2: | |
66 GetCommand()->SetSide2End(scenePos); | |
67 break; | |
68 default: | |
69 throw OrthancException(ErrorCode_InternalError, | |
70 "Wrong state in CreateAngleMeasureTracker::" | |
71 "PointerMove: state_ invalid"); | |
72 } | |
73 //LOG(TRACE) << "scenePos.GetX() = " << scenePos.GetX() << " " << | |
74 // "scenePos.GetY() = " << scenePos.GetY(); | |
75 } | |
76 | |
77 void CreateAngleMeasureTracker::PointerUp(const PointerEvent& e) | |
78 { | |
79 // TODO: the current app does not prevent multiple PointerDown AND | |
80 // PointerUp to be sent to the tracker. | |
81 // Unless we augment the PointerEvent structure with the button index, | |
82 // we cannot really tell if this pointer up event matches the initial | |
83 // pointer down event. Let's make it simple for now. | |
84 | |
85 switch (state_) | |
86 { | |
87 case CreatingSide1: | |
88 state_ = CreatingSide2; | |
89 break; | |
90 case CreatingSide2: | |
91 throw OrthancException(ErrorCode_InternalError, | |
92 "Wrong state in CreateAngleMeasureTracker::" | |
93 "PointerUp: state_ == CreatingSide2 ; this should not happen"); | |
94 break; | |
95 default: | |
96 throw OrthancException(ErrorCode_InternalError, | |
97 "Wrong state in CreateAngleMeasureTracker::" | |
98 "PointerMove: state_ invalid"); | |
99 } | |
100 } | |
101 | |
102 void CreateAngleMeasureTracker::PointerDown(const PointerEvent& e) | |
103 { | |
104 switch (state_) | |
105 { | |
106 case CreatingSide1: | |
107 throw OrthancException(ErrorCode_InternalError, | |
108 "Wrong state in CreateAngleMeasureTracker::" | |
109 "PointerDown: state_ == CreatingSide1 ; this should not happen"); | |
110 break; | |
111 case CreatingSide2: | |
112 // we are done | |
113 alive_ = false; | |
114 break; | |
115 default: | |
116 throw OrthancException(ErrorCode_InternalError, | |
117 "Wrong state in CreateAngleMeasureTracker::" | |
118 "PointerMove: state_ invalid"); | |
119 } | |
120 } | |
121 | |
122 CreateAngleMeasureCommandPtr CreateAngleMeasureTracker::GetCommand() | |
123 { | |
124 return boost::dynamic_pointer_cast<CreateAngleMeasureCommand>(command_); | |
125 } | |
126 | |
127 } |