CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxCameraStyle.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxCameraStyle.h"
34 
35 #include <QAction>
36 #include "cxLogger.h"
37 #include "cxView.h"
38 #include "cxViewGroup.h"
39 #include "cxLogger.h"
40 
41 namespace cx
42 {
43 
45  mCameraStyle(cstDEFAULT_STYLE),
46  mBackend(backend)
47 {
48 }
49 
51 {
52  if (!view || view->getType()!=View::VIEW_3D)
53  return;
54 
55  CameraStyleForViewPtr style(new CameraStyleForView(mBackend));
56  style->setView(view);
57  style->setCameraStyle(mCameraStyle);
58  mViews.push_back(style);
59 }
60 
62 {
63  mViews.clear();
64 }
65 
66 CAMERA_STYLE_TYPE CameraStyle::getCameraStyle() const
67 {
68  return mCameraStyle;
69 }
70 
71 void CameraStyle::setCameraStyle(CAMERA_STYLE_TYPE style)
72 {
73  if (mCameraStyle == style)
74  return;
75 
76  for (unsigned i=0; i<mViews.size(); ++i)
77  mViews[i]->setCameraStyle(style);
78  mCameraStyle = style;
79 
80  emit cameraStyleChanged();
81  report(QString("Activated camera style %1.").arg(enum2string(style)));
82 }
83 
87 
89  mCameraStyleGroup(NULL)
90 {
91 }
92 
94 {
95  if (mStyle)
96  disconnect(mStyle.get(), SIGNAL(cameraStyleChanged()), this, SLOT(updateActionGroup()));
97  mStyle = style;
98  if (mStyle)
99  connect(mStyle.get(), SIGNAL(cameraStyleChanged()), this, SLOT(updateActionGroup()));
100  this->updateActionGroup();
101 }
102 
104 {
105  if (mCameraStyleGroup)
106  return mCameraStyleGroup;
107 
108  mCameraStyleGroup = new QActionGroup(this);
109  mCameraStyleGroup->setExclusive(true);
110 
111  this->addInteractorStyleAction("Normal Camera", mCameraStyleGroup,
113  QIcon(":/icons/camera-n.png"),
114  "Set 3D interaction to the normal camera-oriented style.");
115  this->addInteractorStyleAction("Tool", mCameraStyleGroup,
117  QIcon(":/icons/camera-t.png"),
118  "Camera following tool.");
119  this->addInteractorStyleAction("Angled Tool", mCameraStyleGroup,
121  QIcon(":/icons/camera-at.png"),
122  "Camera following tool (Placed at an angle of 20 degrees).");
123  this->addInteractorStyleAction("Unicam", mCameraStyleGroup,
125  QIcon(":/icons/camera-u.png"),
126  "Set 3D interaction to a single-button style, useful for touch screens.");
127 
128  return mCameraStyleGroup;
129 }
130 
131 void CameraStyleInteractor::addInteractorStyleAction(QString caption, QActionGroup* group, QString uid, QIcon icon,
132  QString helptext)
133 {
134  QAction* action = new QAction(caption, group);
135  action->setIcon(icon);
136  action->setCheckable(true);
137  action->setData(uid);
138  action->setToolTip(helptext);
139  action->setWhatsThis(helptext);
140  connect(action, SIGNAL(triggered(bool)), this, SLOT(setInteractionStyleActionSlot()));
141 }
142 
143 void CameraStyleInteractor::updateActionGroup()
144 {
145  QString currentStyle;
146  if (mStyle)
147  currentStyle = enum2string(mStyle->getCameraStyle());
148 
149  QList<QAction*> actions = mCameraStyleGroup->actions();
150  for (int i=0; i<actions.size(); ++i)
151  {
152  actions[i]->blockSignals(true);
153  actions[i]->setChecked(actions[i]->data().toString() == currentStyle);
154  actions[i]->setEnabled(mStyle!=0);
155  actions[i]->blockSignals(false);
156  }
157 
158 }
159 
160 void CameraStyleInteractor::setInteractionStyleActionSlot()
161 {
162  QAction* theAction = static_cast<QAction*>(sender());
163  if(!theAction)
164  return;
165 
166  QString uid = theAction->data().toString();
167  CAMERA_STYLE_TYPE newStyle = string2enum<cx::CAMERA_STYLE_TYPE>(uid);
168  if (newStyle==cstCOUNT)
169  return;
170 
171  if (mStyle)
172  mStyle->setCameraStyle(newStyle);
173 }
174 
175 
176 
177 }//namespace cx
void setCameraStyle(CAMERA_STYLE_TYPE style)
Select tool style. This replaces the vtkInteractor Style.
QActionGroup * createInteractorStyleActionGroup()
CAMERA_STYLE_TYPE getCameraStyle() const
void addView(ViewPtr view)
boost::shared_ptr< class CameraStyle > CameraStylePtr
Definition: cxCameraStyle.h:57
boost::shared_ptr< class View > ViewPtr
cstUNICAM_STYLE
CameraStyle(CoreServicesPtr backend)
boost::shared_ptr< class CameraStyleForView > CameraStyleForViewPtr
cstDEFAULT_STYLE
void cameraStyleChanged()
void report(QString msg)
Definition: cxLogger.cpp:90
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:59
void connectCameraStyle(CameraStylePtr style)
cstANGLED_TOOL_STYLE
QString enum2string(const ENUM &val)