comparison OrthancStone/Sources/Scene2DViewport/CreateLineMeasureTracker.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/CreateLineMeasureTracker.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 "CreateLineMeasureTracker.h"
22 #include "CreateLineMeasureCommand.h"
23
24 #include <OrthancException.h>
25
26 namespace OrthancStone
27 {
28 CreateLineMeasureTracker::CreateLineMeasureTracker(
29 boost::shared_ptr<IViewport> viewport,
30 const PointerEvent& e)
31 : CreateMeasureTracker(viewport)
32 {
33 ScenePoint2D point = e.GetMainPosition();
34 {
35 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
36 ViewportController& controller = lock->GetController();
37 point = e.GetMainPosition().Apply(controller.GetScene().GetCanvasToSceneTransform());
38 }
39 command_.reset(new CreateLineMeasureCommand(viewport, point));
40 }
41
42 CreateLineMeasureTracker::~CreateLineMeasureTracker()
43 {
44
45 }
46
47 void CreateLineMeasureTracker::PointerMove(const PointerEvent& event)
48 {
49 if (!alive_)
50 {
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
52 "Internal error: wrong state in CreateLineMeasureTracker::"
53 "PointerMove: active_ == false");
54 }
55
56 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
57 ViewportController& controller = lock->GetController();
58
59 ScenePoint2D scenePos = event.GetMainPosition().Apply(
60 controller.GetScene().GetCanvasToSceneTransform());
61
62 //LOG(TRACE) << "scenePos.GetX() = " << scenePos.GetX() << " " <<
63 // "scenePos.GetY() = " << scenePos.GetY();
64
65 CreateLineMeasureTracker* concreteThis =
66 dynamic_cast<CreateLineMeasureTracker*>(this);
67 assert(concreteThis != NULL);
68 GetCommand()->SetEnd(scenePos);
69 }
70
71 void CreateLineMeasureTracker::PointerUp(const PointerEvent& e)
72 {
73 // TODO: the current app does not prevent multiple PointerDown AND
74 // PointerUp to be sent to the tracker.
75 // Unless we augment the PointerEvent structure with the button index,
76 // we cannot really tell if this pointer up event matches the initial
77 // pointer down event. Let's make it simple for now.
78 alive_ = false;
79 }
80
81 void CreateLineMeasureTracker::PointerDown(const PointerEvent& e)
82 {
83 LOG(WARNING) << "Additional touches (fingers, pen, mouse buttons...) "
84 "are ignored when the line measure creation tracker is active";
85 }
86
87 boost::shared_ptr<CreateLineMeasureCommand> CreateLineMeasureTracker::GetCommand()
88 {
89 return boost::dynamic_pointer_cast<CreateLineMeasureCommand>(command_);
90 }
91 }