Mercurial > hg > orthanc-stone
annotate Samples/Common/CreateLineMeasureTracker.cpp @ 679:979963fd3725
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 16 May 2019 11:20:59 +0200 |
parents | 462a5074f914 |
children |
rev | line source |
---|---|
644 | 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 "CreateLineMeasureTracker.h" | |
22 #include <Core/OrthancException.h> | |
23 | |
24 using namespace Orthanc; | |
25 | |
26 namespace OrthancStone | |
27 { | |
28 CreateLineMeasureTracker::CreateLineMeasureTracker( | |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
29 MessageBroker& broker, |
644 | 30 Scene2D& scene, |
31 std::vector<TrackerCommandPtr>& undoStack, | |
32 std::vector<MeasureToolPtr>& measureTools, | |
33 const PointerEvent& e) | |
34 : CreateMeasureTracker(scene, undoStack, measureTools) | |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
35 { |
644 | 36 command_.reset( |
37 new CreateLineMeasureCommand( | |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
38 broker, |
644 | 39 scene, |
40 measureTools, | |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
41 e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform()))); |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
42 } |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
43 |
644 | 44 CreateLineMeasureTracker::~CreateLineMeasureTracker() |
45 { | |
46 | |
47 } | |
48 | |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
49 void CreateLineMeasureTracker::PointerMove(const PointerEvent& event) |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
50 { |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
51 if (!active_) |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
52 { |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
53 throw OrthancException(ErrorCode_InternalError, |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
54 "Internal error: wrong state in CreateLineMeasureTracker::" |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
55 "PointerMove: active_ == false"); |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
56 } |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
57 |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
58 ScenePoint2D scenePos = event.GetMainPosition().Apply( |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
59 scene_.GetCanvasToSceneTransform()); |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
60 |
644 | 61 //LOG(TRACE) << "scenePos.GetX() = " << scenePos.GetX() << " " << |
62 // "scenePos.GetY() = " << scenePos.GetY(); | |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
63 |
644 | 64 CreateLineMeasureTracker* concreteThis = |
65 dynamic_cast<CreateLineMeasureTracker*>(this); | |
66 assert(concreteThis != NULL); | |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
67 GetCommand()->SetEnd(scenePos); |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
68 } |
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
69 |
644 | 70 void CreateLineMeasureTracker::PointerUp(const PointerEvent& e) |
71 { | |
72 // TODO: the current app does not prevent multiple PointerDown AND | |
73 // PointerUp to be sent to the tracker. | |
74 // Unless we augment the PointerEvent structure with the button index, | |
75 // we cannot really tell if this pointer up event matches the initial | |
76 // pointer down event. Let's make it simple for now. | |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
645
diff
changeset
|
77 active_ = false; |
644 | 78 } |
79 | |
80 void CreateLineMeasureTracker::PointerDown(const PointerEvent& e) | |
81 { | |
82 LOG(WARNING) << "Additional touches (fingers, pen, mouse buttons...) " | |
83 "are ignored when the line measure creation tracker is active"; | |
84 } | |
645
1e9ed656318e
Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
85 |
1e9ed656318e
Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
86 CreateLineMeasureCommandPtr CreateLineMeasureTracker::GetCommand() |
1e9ed656318e
Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
87 { |
1e9ed656318e
Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
88 return boost::dynamic_pointer_cast<CreateLineMeasureCommand>(command_); |
1e9ed656318e
Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
89 } |
1e9ed656318e
Merge + ongoing measure work
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
90 |
644 | 91 } |