Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Scene2DViewport/EditLineMeasureTracker.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/EditLineMeasureTracker.cpp@ab81ee8fce1f |
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 "EditLineMeasureTracker.h" | |
22 #include "EditLineMeasureCommand.h" | |
23 | |
24 #include "../StoneException.h" | |
25 | |
26 | |
27 namespace OrthancStone | |
28 { | |
29 EditLineMeasureTracker::EditLineMeasureTracker( | |
30 boost::shared_ptr<MeasureTool> measureTool, | |
31 boost::shared_ptr<IViewport> viewport, | |
32 const PointerEvent& e) | |
33 : EditMeasureTracker(viewport, e) | |
34 { | |
35 ScenePoint2D scenePos = e.GetMainPosition(); | |
36 { | |
37 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | |
38 Scene2D& scene = lock->GetController().GetScene(); | |
39 scenePos = e.GetMainPosition().Apply(scene.GetCanvasToSceneTransform()); | |
40 } | |
41 modifiedZone_ = dynamic_cast<LineMeasureTool&>(*measureTool).LineHitTest(scenePos); | |
42 command_.reset(new EditLineMeasureCommand(measureTool, viewport)); | |
43 } | |
44 | |
45 EditLineMeasureTracker::~EditLineMeasureTracker() | |
46 { | |
47 | |
48 } | |
49 | |
50 void EditLineMeasureTracker::PointerMove(const PointerEvent& e) | |
51 { | |
52 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | |
53 ViewportController& controller = lock->GetController(); | |
54 Scene2D& scene = controller.GetScene(); | |
55 | |
56 ScenePoint2D scenePos = e.GetMainPosition().Apply( | |
57 scene.GetCanvasToSceneTransform()); | |
58 | |
59 ScenePoint2D delta = scenePos - GetOriginalClickPosition(); | |
60 | |
61 boost::shared_ptr<LineMeasureToolMemento> memento = | |
62 boost::dynamic_pointer_cast<LineMeasureToolMemento>(command_->mementoOriginal_); | |
63 | |
64 ORTHANC_ASSERT(memento.get() != NULL); | |
65 | |
66 switch (modifiedZone_) | |
67 { | |
68 case LineMeasureTool::LineHighlightArea_Start: | |
69 { | |
70 ScenePoint2D newStart = memento->start_ + delta; | |
71 GetCommand()->SetStart(newStart); | |
72 } | |
73 break; | |
74 case LineMeasureTool::LineHighlightArea_End: | |
75 { | |
76 ScenePoint2D newEnd = memento->end_ + delta; | |
77 GetCommand()->SetEnd(newEnd); | |
78 } | |
79 break; | |
80 case LineMeasureTool::LineHighlightArea_Segment: | |
81 { | |
82 ScenePoint2D newStart = memento->start_ + delta; | |
83 ScenePoint2D newEnd = memento->end_ + delta; | |
84 GetCommand()->SetStart(newStart); | |
85 GetCommand()->SetEnd(newEnd); | |
86 } | |
87 break; | |
88 default: | |
89 LOG(WARNING) << "Warning: please retry the measuring tool editing operation!"; | |
90 break; | |
91 } | |
92 } | |
93 | |
94 void EditLineMeasureTracker::PointerUp(const PointerEvent& e) | |
95 { | |
96 alive_ = false; | |
97 } | |
98 | |
99 void EditLineMeasureTracker::PointerDown(const PointerEvent& e) | |
100 { | |
101 LOG(WARNING) << "Additional touches (fingers, pen, mouse buttons...) " | |
102 "are ignored when the edit line tracker is active"; | |
103 } | |
104 | |
105 boost::shared_ptr<EditLineMeasureCommand> EditLineMeasureTracker::GetCommand() | |
106 { | |
107 boost::shared_ptr<EditLineMeasureCommand> ret = boost::dynamic_pointer_cast<EditLineMeasureCommand>(command_); | |
108 ORTHANC_ASSERT(ret.get() != NULL, "Internal error in EditLineMeasureTracker::GetCommand()"); | |
109 return ret; | |
110 } | |
111 | |
112 } |