comparison OrthancStone/Sources/Scene2DViewport/CreateAngleMeasureTracker.cpp @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Scene2DViewport/CreateAngleMeasureTracker.cpp@30deba7bc8e2
children 85e117739eca
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
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-2020 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 "CreateAngleMeasureCommand.h"
23
24 #include <OrthancException.h>
25
26 namespace OrthancStone
27 {
28 CreateAngleMeasureTracker::CreateAngleMeasureTracker(
29 boost::shared_ptr<IViewport> viewport,
30 const PointerEvent& e)
31 : CreateMeasureTracker(viewport)
32 , state_(CreatingSide1)
33 {
34 ScenePoint2D point = e.GetMainPosition();
35 {
36 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
37 Scene2D& scene = lock->GetController().GetScene();
38 point = e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform());
39 }
40 command_.reset(new CreateAngleMeasureCommand(viewport, point));
41 }
42
43 CreateAngleMeasureTracker::~CreateAngleMeasureTracker()
44 {
45 }
46
47 void CreateAngleMeasureTracker::PointerMove(const PointerEvent& event)
48 {
49 if (!alive_)
50 {
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
52 "Internal error: wrong state in CreateAngleMeasureTracker::"
53 "PointerMove: active_ == false");
54 }
55
56
57 {
58 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
59 ViewportController& controller = lock->GetController();
60
61 ScenePoint2D scenePos = event.GetMainPosition().Apply(
62 controller.GetScene().GetCanvasToSceneTransform());
63
64 switch (state_)
65 {
66 case CreatingSide1:
67 GetCommand()->SetCenter(scenePos);
68 break;
69 case CreatingSide2:
70 GetCommand()->SetSide2End(scenePos);
71 break;
72 default:
73 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
74 "Wrong state in CreateAngleMeasureTracker::"
75 "PointerMove: state_ invalid");
76 }
77 //LOG(TRACE) << "scenePos.GetX() = " << scenePos.GetX() << " " <<
78 // "scenePos.GetY() = " << scenePos.GetY();
79 lock->Invalidate();
80 }
81 }
82
83 void CreateAngleMeasureTracker::PointerUp(const PointerEvent& e)
84 {
85 // TODO: the current app does not prevent multiple PointerDown AND
86 // PointerUp to be sent to the tracker.
87 // Unless we augment the PointerEvent structure with the button index,
88 // we cannot really tell if this pointer up event matches the initial
89 // pointer down event. Let's make it simple for now.
90
91 switch (state_)
92 {
93 case CreatingSide1:
94 state_ = CreatingSide2;
95 break;
96 case CreatingSide2:
97 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
98 "Wrong state in CreateAngleMeasureTracker::"
99 "PointerUp: state_ == CreatingSide2 ; this should not happen");
100 break;
101 default:
102 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
103 "Wrong state in CreateAngleMeasureTracker::"
104 "PointerMove: state_ invalid");
105 }
106 }
107
108 void CreateAngleMeasureTracker::PointerDown(const PointerEvent& e)
109 {
110 switch (state_)
111 {
112 case CreatingSide1:
113 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
114 "Wrong state in CreateAngleMeasureTracker::"
115 "PointerDown: state_ == CreatingSide1 ; this should not happen");
116 break;
117 case CreatingSide2:
118 // we are done
119 alive_ = false;
120 break;
121 default:
122 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
123 "Wrong state in CreateAngleMeasureTracker::"
124 "PointerMove: state_ invalid");
125 }
126 }
127
128 boost::shared_ptr<CreateAngleMeasureCommand> CreateAngleMeasureTracker::GetCommand()
129 {
130 return boost::dynamic_pointer_cast<CreateAngleMeasureCommand>(command_);
131 }
132
133 }