Mercurial > hg > orthanc-stone
comparison Framework/Scene2DViewport/ViewportController.cpp @ 727:853e30d17cae
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 May 2019 11:45:06 +0200 |
parents | 28b9e3a54200 |
children | c0fcb2757b0a 712ff6ff3c19 |
comparison
equal
deleted
inserted
replaced
726:4f2416d519b4 | 727:853e30d17cae |
---|---|
17 * You should have received a copy of the GNU Affero General Public License | 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/>. | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 **/ |
20 | 20 |
21 #include "ViewportController.h" | 21 #include "ViewportController.h" |
22 #include "MeasureCommands.h" | |
22 | 23 |
23 #include <Framework/StoneException.h> | 24 #include <Framework/StoneException.h> |
24 | 25 |
25 #include <boost/make_shared.hpp> | 26 #include <boost/make_shared.hpp> |
26 | 27 |
28 | 29 |
29 namespace OrthancStone | 30 namespace OrthancStone |
30 { | 31 { |
31 ViewportController::ViewportController(MessageBroker& broker) | 32 ViewportController::ViewportController(MessageBroker& broker) |
32 : IObservable(broker) | 33 : IObservable(broker) |
34 , numAppliedCommands_(0) | |
33 { | 35 { |
34 scene_ = boost::make_shared<Scene2D>(); | 36 scene_ = boost::make_shared<Scene2D>(); |
35 } | 37 } |
36 | 38 |
37 Scene2DPtr ViewportController::GetScene() | 39 Scene2DPtr ViewportController::GetScene() |
40 } | 42 } |
41 | 43 |
42 bool ViewportController::HandlePointerEvent(PointerEvent e) | 44 bool ViewportController::HandlePointerEvent(PointerEvent e) |
43 { | 45 { |
44 throw StoneException(ErrorCode_NotImplemented); | 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; | |
45 } | 60 } |
46 | 61 |
47 const OrthancStone::AffineTransform2D& ViewportController::GetCanvasToSceneTransform() const | 62 const OrthancStone::AffineTransform2D& ViewportController::GetCanvasToSceneTransform() const |
48 { | 63 { |
49 return scene_->GetCanvasToSceneTransform(); | 64 return scene_->GetCanvasToSceneTransform(); |
59 { | 74 { |
60 scene_->SetSceneToCanvasTransform(transform); | 75 scene_->SetSceneToCanvasTransform(transform); |
61 BroadcastMessage(SceneTransformChanged(*this)); | 76 BroadcastMessage(SceneTransformChanged(*this)); |
62 } | 77 } |
63 | 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 | |
64 } | 136 } |
65 | 137 |