Mercurial > hg > orthanc-stone
comparison Framework/Scene2DViewport/EditLineMeasureTracker.cpp @ 866:c71ef52602a0 toa2019062501
Added the ability to edit existing measuring tools (demo not updated yet)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 25 Jun 2019 17:54:46 +0200 |
parents | |
children | 60a403f01c31 |
comparison
equal
deleted
inserted
replaced
865:a29c13497557 | 866:c71ef52602a0 |
---|---|
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 "EditLineMeasureTracker.h" | |
22 | |
23 namespace OrthancStone | |
24 { | |
25 EditLineMeasureTracker::EditLineMeasureTracker( | |
26 boost::shared_ptr<LineMeasureTool> measureTool, | |
27 MessageBroker& broker, | |
28 boost::weak_ptr<ViewportController> controllerW, | |
29 const PointerEvent& e) | |
30 : EditMeasureTracker(controllerW, e) | |
31 { | |
32 ScenePoint2D scenePos = e.GetMainPosition().Apply( | |
33 GetScene()->GetCanvasToSceneTransform()); | |
34 | |
35 modifiedZone_ = measureTool->LineHitTest(scenePos); | |
36 | |
37 command_.reset( | |
38 new EditLineMeasureCommand( | |
39 measureTool, | |
40 broker, | |
41 controllerW)); | |
42 } | |
43 | |
44 EditLineMeasureTracker::~EditLineMeasureTracker() | |
45 { | |
46 | |
47 } | |
48 | |
49 void EditLineMeasureTracker::PointerMove(const PointerEvent& e) | |
50 { | |
51 ScenePoint2D scenePos = e.GetMainPosition().Apply( | |
52 GetScene()->GetCanvasToSceneTransform()); | |
53 | |
54 ScenePoint2D delta = scenePos - GetOriginalClickPosition(); | |
55 | |
56 boost::shared_ptr<LineMeasureToolMemento> memento = | |
57 boost::dynamic_pointer_cast<LineMeasureToolMemento>(command_->mementoOriginal_); | |
58 | |
59 ORTHANC_ASSERT(memento.get() != NULL); | |
60 | |
61 switch (modifiedZone_) | |
62 { | |
63 case LineMeasureTool::LineHighlightArea_Start: | |
64 { | |
65 ScenePoint2D newStart = memento->start_ + delta; | |
66 GetCommand()->SetStart(newStart); | |
67 } | |
68 break; | |
69 case LineMeasureTool::LineHighlightArea_End: | |
70 { | |
71 ScenePoint2D newEnd = memento->end_ + delta; | |
72 GetCommand()->SetEnd(newEnd); | |
73 } | |
74 break; | |
75 case LineMeasureTool::LineHighlightArea_Segment: | |
76 { | |
77 ScenePoint2D newStart = memento->start_ + delta; | |
78 ScenePoint2D newEnd = memento->end_ + delta; | |
79 GetCommand()->SetStart(newStart); | |
80 GetCommand()->SetEnd(newEnd); | |
81 } | |
82 break; | |
83 default: | |
84 LOG(WARN) << "Warning: please retry the measuring tool editing operation!"; | |
85 break; | |
86 } | |
87 } | |
88 | |
89 void EditLineMeasureTracker::PointerUp(const PointerEvent& e) | |
90 { | |
91 alive_ = false; | |
92 } | |
93 | |
94 void EditLineMeasureTracker::PointerDown(const PointerEvent& e) | |
95 { | |
96 LOG(WARNING) << "Additional touches (fingers, pen, mouse buttons...) " | |
97 "are ignored when the edit line tracker is active"; | |
98 } | |
99 | |
100 boost::shared_ptr<EditLineMeasureCommand> EditLineMeasureTracker::GetCommand() | |
101 { | |
102 boost::shared_ptr<EditLineMeasureCommand> ret = boost::dynamic_pointer_cast<EditLineMeasureCommand>(command_); | |
103 ORTHANC_ASSERT(ret.get() != NULL, "Internal error in EditLineMeasureTracker::GetCommand()"); | |
104 return ret; | |
105 } | |
106 | |
107 } |