Mercurial > hg > orthanc-stone
comparison Framework/Scene2DViewport/ViewportController.cpp @ 728:8190213e2279 am-dev
Merged default into am-dev
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 21 May 2019 13:25:58 +0200 |
parents | 28b9e3a54200 |
children | c0fcb2757b0a 712ff6ff3c19 |
comparison
equal
deleted
inserted
replaced
690:f185cfcb72a0 | 728:8190213e2279 |
---|---|
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 "ViewportController.h" | |
22 #include "MeasureCommands.h" | |
23 | |
24 #include <Framework/StoneException.h> | |
25 | |
26 #include <boost/make_shared.hpp> | |
27 | |
28 using namespace Orthanc; | |
29 | |
30 namespace OrthancStone | |
31 { | |
32 ViewportController::ViewportController(MessageBroker& broker) | |
33 : IObservable(broker) | |
34 , numAppliedCommands_(0) | |
35 { | |
36 scene_ = boost::make_shared<Scene2D>(); | |
37 } | |
38 | |
39 Scene2DPtr ViewportController::GetScene() | |
40 { | |
41 return scene_; | |
42 } | |
43 | |
44 bool ViewportController::HandlePointerEvent(PointerEvent e) | |
45 { | |
46 throw StoneException(ErrorCode_NotImplemented); | |
47 } | |
48 | |
49 std::vector<MeasureToolPtr> ViewportController::HitTestMeasureTools( | |
50 ScenePoint2D p) | |
51 { | |
52 std::vector<MeasureToolPtr> ret; | |
53 | |
54 | |
55 //for (size_t i = 0; i < measureTools_.size(); ++i) | |
56 //{ | |
57 | |
58 //} | |
59 return ret; | |
60 } | |
61 | |
62 const OrthancStone::AffineTransform2D& ViewportController::GetCanvasToSceneTransform() const | |
63 { | |
64 return scene_->GetCanvasToSceneTransform(); | |
65 } | |
66 | |
67 const OrthancStone::AffineTransform2D& ViewportController::GetSceneToCanvasTransform() const | |
68 { | |
69 return scene_->GetSceneToCanvasTransform(); | |
70 } | |
71 | |
72 void ViewportController::SetSceneToCanvasTransform( | |
73 const AffineTransform2D& transform) | |
74 { | |
75 scene_->SetSceneToCanvasTransform(transform); | |
76 BroadcastMessage(SceneTransformChanged(*this)); | |
77 } | |
78 | |
79 void ViewportController::FitContent( | |
80 unsigned int canvasWidth, unsigned int canvasHeight) | |
81 { | |
82 scene_->FitContent(canvasWidth, canvasHeight); | |
83 BroadcastMessage(SceneTransformChanged(*this)); | |
84 } | |
85 | |
86 void ViewportController::PushCommand(TrackerCommandPtr command) | |
87 { | |
88 commandStack_.erase( | |
89 commandStack_.begin() + numAppliedCommands_, | |
90 commandStack_.end()); | |
91 | |
92 ORTHANC_ASSERT(std::find(commandStack_.begin(), commandStack_.end(), command) | |
93 == commandStack_.end(), "Duplicate command"); | |
94 commandStack_.push_back(command); | |
95 numAppliedCommands_++; | |
96 } | |
97 | |
98 void ViewportController::Undo() | |
99 { | |
100 ORTHANC_ASSERT(CanUndo(), ""); | |
101 commandStack_[numAppliedCommands_-1]->Undo(); | |
102 numAppliedCommands_--; | |
103 } | |
104 | |
105 void ViewportController::Redo() | |
106 { | |
107 ORTHANC_ASSERT(CanRedo(), ""); | |
108 commandStack_[numAppliedCommands_]->Redo(); | |
109 numAppliedCommands_++; | |
110 } | |
111 | |
112 bool ViewportController::CanUndo() const | |
113 { | |
114 return numAppliedCommands_ > 0; | |
115 } | |
116 | |
117 bool ViewportController::CanRedo() const | |
118 { | |
119 return numAppliedCommands_ < commandStack_.size(); | |
120 } | |
121 | |
122 void ViewportController::AddMeasureTool(MeasureToolPtr measureTool) | |
123 { | |
124 ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool) | |
125 == measureTools_.end(), "Duplicate measure tool"); | |
126 measureTools_.push_back(measureTool); | |
127 } | |
128 | |
129 void ViewportController::RemoveMeasureTool(MeasureToolPtr measureTool) | |
130 { | |
131 ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool) | |
132 != measureTools_.end(), "Measure tool not found"); | |
133 measureTools_.push_back(measureTool); | |
134 } | |
135 | |
136 } | |
137 |