Fraxinus  16.5.0-fx-rc9
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  return mCameraStyleGroup;
128 }
129 
130 void CameraStyleInteractor::addInteractorStyleAction(QString caption, QActionGroup* group, QString uid, QIcon icon,
131  QString helptext)
132 {
133  QAction* action = new QAction(caption, group);
134  action->setIcon(icon);
135  action->setCheckable(true);
136  action->setData(uid);
137  action->setToolTip(helptext);
138  action->setWhatsThis(helptext);
139  connect(action, SIGNAL(triggered(bool)), this, SLOT(setInteractionStyleActionSlot()));
140 }
141 
142 void CameraStyleInteractor::updateActionGroup()
143 {
144  QString currentStyle;
145  if (mStyle)
146  currentStyle = enum2string(mStyle->getCameraStyle());
147 
148  if(mCameraStyleGroup)
149  {
150  QList<QAction*> actions = mCameraStyleGroup->actions();
151  for (int i=0; i<actions.size(); ++i)
152  {
153  actions[i]->setEnabled(mStyle!=0);
154  bool check = actions[i]->data().toString() == currentStyle;
155  if(actions[i]->isChecked() != check)
156  actions[i]->setChecked(check);
157  }
158  }
159 }
160 
161 void CameraStyleInteractor::setInteractionStyleActionSlot()
162 {
163  QAction* theAction = static_cast<QAction*>(sender());
164  if(!theAction)
165  return;
166 
167  QString uid = theAction->data().toString();
168  CAMERA_STYLE_TYPE newStyle = string2enum<cx::CAMERA_STYLE_TYPE>(uid);
169  if (newStyle==cstCOUNT)
170  return;
171 
172  if (mStyle)
173  mStyle->setCameraStyle(newStyle);
174 }
175 
176 
177 
178 }//namespace cx
void setCameraStyle(CAMERA_STYLE_TYPE style)
Select tool style. This replaces the vtkInteractor Style.
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
cstTOOL_STYLE
Definition: cxViewService.h:61
cstDEFAULT_STYLE
Definition: cxViewService.h:61
QActionGroup * getInteractorStyleActionGroup()
CameraStyle(CoreServicesPtr backend)
cstANGLED_TOOL_STYLE
Definition: cxViewService.h:61
boost::shared_ptr< class CameraStyleForView > CameraStyleForViewPtr
void cameraStyleChanged()
void report(QString msg)
Definition: cxLogger.cpp:90
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:59
cstUNICAM_STYLE
Definition: cxViewService.h:61
void connectCameraStyle(CameraStylePtr style)
QString enum2string(const ENUM &val)