Mercurial > hg > orthanc-stone
comparison Samples/Common/CreateAngleMeasureTracker.cpp @ 645:1e9ed656318e
Merge + ongoing measure work
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 13 May 2019 15:12:56 +0200 |
parents | f939f449482c |
children | 462a5074f914 |
comparison
equal
deleted
inserted
replaced
644:f939f449482c | 645:1e9ed656318e |
---|---|
16 * | 16 * |
17 * You should have received a copy of the GNU Affero General Public License | 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/>. | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 **/ |
20 | 20 |
21 #include "CreateAngleMeasureTracker.h" | |
22 #include <Core/OrthancException.h> | |
23 | |
24 using namespace Orthanc; | |
25 | |
21 namespace OrthancStone | 26 namespace OrthancStone |
22 { | 27 { |
28 CreateAngleMeasureTracker::CreateAngleMeasureTracker( | |
29 Scene2D& scene, | |
30 std::vector<TrackerCommandPtr>& undoStack, | |
31 std::vector<MeasureToolPtr>& measureTools, | |
32 const PointerEvent& e) | |
33 : CreateMeasureTracker(scene, undoStack, measureTools) | |
34 , state_(CreatingSide1) | |
35 { | |
36 command_.reset( | |
37 new CreateAngleMeasureCommand( | |
38 scene, | |
39 measureTools, | |
40 e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform()))); | |
41 } | |
42 | |
43 CreateAngleMeasureTracker::~CreateAngleMeasureTracker() | |
44 { | |
45 } | |
46 | |
47 void CreateAngleMeasureTracker::PointerMove(const PointerEvent& event) | |
48 { | |
49 if (!active_) | |
50 { | |
51 throw OrthancException(ErrorCode_InternalError, | |
52 "Internal error: wrong state in CreateAngleMeasureTracker::" | |
53 "PointerMove: active_ == false"); | |
54 } | |
55 | |
56 ScenePoint2D scenePos = event.GetMainPosition().Apply( | |
57 scene_.GetCanvasToSceneTransform()); | |
58 | |
59 switch (state_) | |
60 { | |
61 case CreatingSide1: | |
62 GetCommand()->SetCenter(scenePos); | |
63 break; | |
64 case CreatingSide2: | |
65 GetCommand()->SetSide2End(scenePos); | |
66 break; | |
67 default: | |
68 throw OrthancException(ErrorCode_InternalError, | |
69 "Wrong state in CreateAngleMeasureTracker::" | |
70 "PointerMove: state_ invalid"); | |
71 } | |
72 //LOG(TRACE) << "scenePos.GetX() = " << scenePos.GetX() << " " << | |
73 // "scenePos.GetY() = " << scenePos.GetY(); | |
74 } | |
75 | |
76 void CreateAngleMeasureTracker::PointerUp(const PointerEvent& e) | |
77 { | |
78 // TODO: the current app does not prevent multiple PointerDown AND | |
79 // PointerUp to be sent to the tracker. | |
80 // Unless we augment the PointerEvent structure with the button index, | |
81 // we cannot really tell if this pointer up event matches the initial | |
82 // pointer down event. Let's make it simple for now. | |
83 | |
84 switch (state_) | |
85 { | |
86 case CreatingSide1: | |
87 state_ = CreatingSide2; | |
88 break; | |
89 case CreatingSide2: | |
90 throw OrthancException(ErrorCode_InternalError, | |
91 "Wrong state in CreateAngleMeasureTracker::" | |
92 "PointerUp: state_ == CreatingSide2 ; this should not happen"); | |
93 break; | |
94 default: | |
95 throw OrthancException(ErrorCode_InternalError, | |
96 "Wrong state in CreateAngleMeasureTracker::" | |
97 "PointerMove: state_ invalid"); | |
98 } | |
99 } | |
100 | |
101 void CreateAngleMeasureTracker::PointerDown(const PointerEvent& e) | |
102 { | |
103 switch (state_) | |
104 { | |
105 case CreatingSide1: | |
106 throw OrthancException(ErrorCode_InternalError, | |
107 "Wrong state in CreateAngleMeasureTracker::" | |
108 "PointerDown: state_ == CreatingSide1 ; this should not happen"); | |
109 break; | |
110 case CreatingSide2: | |
111 // we are done | |
112 active_ = false; | |
113 break; | |
114 default: | |
115 throw OrthancException(ErrorCode_InternalError, | |
116 "Wrong state in CreateAngleMeasureTracker::" | |
117 "PointerMove: state_ invalid"); | |
118 } | |
119 } | |
120 | |
121 CreateAngleMeasureCommandPtr CreateAngleMeasureTracker::GetCommand() | |
122 { | |
123 return boost::dynamic_pointer_cast<CreateAngleMeasureCommand>(command_); | |
124 } | |
125 | |
23 } | 126 } |