comparison Framework/Scene2DViewport/CreateAngleMeasureTracker.cpp @ 698:8b6adfb62a2f refactor-viewport-controller

Code is broken -- stashing ongoing work in a branch
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 15 May 2019 16:56:17 +0200
parents
children 059e1fd05fd6
comparison
equal deleted inserted replaced
660:cb3b76d16234 698:8b6adfb62a2f
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 Scene2DWPtr sceneW,
31 std::vector<TrackerCommandPtr>& undoStack,
32 MeasureToolList& measureTools,
33 const PointerEvent& e)
34 : CreateMeasureTracker(sceneW, undoStack, measureTools)
35 , state_(CreatingSide1)
36 {
37 Scene2DPtr scene = sceneW.lock();
38 command_.reset(
39 new CreateAngleMeasureCommand(
40 broker,
41 sceneW,
42 measureTools,
43 e.GetMainPosition().Apply(scene->GetCanvasToSceneTransform())));
44 }
45
46 CreateAngleMeasureTracker::~CreateAngleMeasureTracker()
47 {
48 }
49
50 void CreateAngleMeasureTracker::PointerMove(const PointerEvent& event)
51 {
52 Scene2DPtr scene = scene_.lock();
53 if (!active_)
54 {
55 throw OrthancException(ErrorCode_InternalError,
56 "Internal error: wrong state in CreateAngleMeasureTracker::"
57 "PointerMove: active_ == false");
58 }
59
60 ScenePoint2D scenePos = event.GetMainPosition().Apply(
61 scene->GetCanvasToSceneTransform());
62
63 switch (state_)
64 {
65 case CreatingSide1:
66 GetCommand()->SetCenter(scenePos);
67 break;
68 case CreatingSide2:
69 GetCommand()->SetSide2End(scenePos);
70 break;
71 default:
72 throw OrthancException(ErrorCode_InternalError,
73 "Wrong state in CreateAngleMeasureTracker::"
74 "PointerMove: state_ invalid");
75 }
76 //LOG(TRACE) << "scenePos.GetX() = " << scenePos.GetX() << " " <<
77 // "scenePos.GetY() = " << scenePos.GetY();
78 }
79
80 void CreateAngleMeasureTracker::PointerUp(const PointerEvent& e)
81 {
82 // TODO: the current app does not prevent multiple PointerDown AND
83 // PointerUp to be sent to the tracker.
84 // Unless we augment the PointerEvent structure with the button index,
85 // we cannot really tell if this pointer up event matches the initial
86 // pointer down event. Let's make it simple for now.
87
88 switch (state_)
89 {
90 case CreatingSide1:
91 state_ = CreatingSide2;
92 break;
93 case CreatingSide2:
94 throw OrthancException(ErrorCode_InternalError,
95 "Wrong state in CreateAngleMeasureTracker::"
96 "PointerUp: state_ == CreatingSide2 ; this should not happen");
97 break;
98 default:
99 throw OrthancException(ErrorCode_InternalError,
100 "Wrong state in CreateAngleMeasureTracker::"
101 "PointerMove: state_ invalid");
102 }
103 }
104
105 void CreateAngleMeasureTracker::PointerDown(const PointerEvent& e)
106 {
107 switch (state_)
108 {
109 case CreatingSide1:
110 throw OrthancException(ErrorCode_InternalError,
111 "Wrong state in CreateAngleMeasureTracker::"
112 "PointerDown: state_ == CreatingSide1 ; this should not happen");
113 break;
114 case CreatingSide2:
115 // we are done
116 active_ = false;
117 break;
118 default:
119 throw OrthancException(ErrorCode_InternalError,
120 "Wrong state in CreateAngleMeasureTracker::"
121 "PointerMove: state_ invalid");
122 }
123 }
124
125 CreateAngleMeasureCommandPtr CreateAngleMeasureTracker::GetCommand()
126 {
127 return boost::dynamic_pointer_cast<CreateAngleMeasureCommand>(command_);
128 }
129
130 }