Mercurial > hg > orthanc-stone
comparison Framework/Scene2DViewport/MeasureTool.cpp @ 774:66ac7a2d1e3a
A few renames and cleanups + moved GUI constants to controller + start work on
hit tests for measure tools and mouse hover.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 24 May 2019 15:59:51 +0200 |
parents | Framework/Scene2DViewport/MeasureTools.cpp@8e31b174ab26 |
children | e42b491f1fb2 |
comparison
equal
deleted
inserted
replaced
761:07adcffba38c | 774:66ac7a2d1e3a |
---|---|
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 "MeasureTool.h" | |
22 | |
23 #include <Core/Logging.h> | |
24 #include <Core/Enumerations.h> | |
25 #include <Core/OrthancException.h> | |
26 | |
27 #include <boost/math/constants/constants.hpp> | |
28 | |
29 namespace OrthancStone | |
30 { | |
31 MeasureTool::~MeasureTool() | |
32 { | |
33 | |
34 } | |
35 | |
36 void MeasureTool::Enable() | |
37 { | |
38 enabled_ = true; | |
39 RefreshScene(); | |
40 } | |
41 | |
42 void MeasureTool::Disable() | |
43 { | |
44 enabled_ = false; | |
45 RefreshScene(); | |
46 } | |
47 | |
48 bool MeasureTool::IsEnabled() const | |
49 { | |
50 return enabled_; | |
51 } | |
52 | |
53 | |
54 ViewportControllerConstPtr MeasureTool::GetController() const | |
55 { | |
56 ViewportControllerConstPtr controller = controllerW_.lock(); | |
57 if (!controller) | |
58 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, | |
59 "Using dead ViewportController object!"); | |
60 return controller; | |
61 } | |
62 | |
63 ViewportControllerPtr MeasureTool::GetController() | |
64 { | |
65 #if 1 | |
66 return boost::const_pointer_cast<ViewportController> | |
67 (const_cast<const MeasureTool*>(this)->GetController()); | |
68 //return boost::const_<ViewportControllerPtr> | |
69 // (const_cast<const MeasureTool*>(this)->GetController()); | |
70 #else | |
71 ViewportControllerPtr controller = controllerW_.lock(); | |
72 if (!controller) | |
73 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, | |
74 "Using dead ViewportController object!"); | |
75 return controller; | |
76 #endif | |
77 } | |
78 | |
79 Scene2DPtr MeasureTool::GetScene() | |
80 { | |
81 return GetController()->GetScene(); | |
82 } | |
83 | |
84 Scene2DConstPtr MeasureTool::GetScene() const | |
85 { | |
86 return GetController()->GetScene(); | |
87 } | |
88 | |
89 MeasureTool::MeasureTool(MessageBroker& broker, | |
90 ViewportControllerWPtr controllerW) | |
91 : IObserver(broker) | |
92 , controllerW_(controllerW) | |
93 , enabled_(true) | |
94 { | |
95 GetController()->RegisterObserverCallback( | |
96 new Callable<MeasureTool, ViewportController::SceneTransformChanged> | |
97 (*this, &MeasureTool::OnSceneTransformChanged)); | |
98 } | |
99 | |
100 | |
101 bool MeasureTool::IsSceneAlive() const | |
102 { | |
103 ViewportControllerPtr controller = controllerW_.lock(); | |
104 return (controller.get() != NULL); | |
105 } | |
106 | |
107 void MeasureTool::OnSceneTransformChanged( | |
108 const ViewportController::SceneTransformChanged& message) | |
109 { | |
110 RefreshScene(); | |
111 } | |
112 | |
113 | |
114 } | |
115 |