Fraxinus  17.12-rc4
An IGT application
cxViewGroupPropertiesWidget.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 
34 #include <QLabel>
35 #include <QGroupBox>
36 #include <QToolBar>
38 #include "cxViewService.h"
39 #include "cxViewGroupData.h"
40 #include "cxStringProperty.h"
41 #include "cxBoolProperty.h"
42 #include "cxVisServices.h"
43 #include "cxHelperWidgets.h"
44 #include "cxLogger.h"
47 
48 namespace cx
49 {
50 
52  VisServicesPtr services,
53  QWidget* parent) :
54  BaseWidget(parent, "ViewGroupPropertiesWidget", "View Properties"),
55  mGroupIndex(groupIndex),
56  mServices(services)
57 {
58  ViewGroupDataPtr group = this->getViewGroup();
60 
61  mLayout = new QVBoxLayout(this);
62  this->setModified();
63 }
64 
66 {
67 }
68 
70 {
71  if (mLayout->count()) // already created
72  return;
73 
74  ViewGroupDataPtr group = this->getViewGroup();
75  if (!group)
76  return;
77 
78  mLayout->setMargin(2);
79 
80  StringListSelectWidget* slices3D = new StringListSelectWidget(this, group->getSliceDefinitionProperty());
81  mLayout->addWidget(slices3D);
82 
83  this->createCameraStyleProperties();
84  this->createCameraStyleWidget();
85 
86  mLayout->addStretch();
87 }
88 
90 {
91  this->setupUI();
92  this->updateFrontend();
93 }
94 
95 void ViewGroupPropertiesWidget::updateFrontend()
96 {
97  ViewGroupDataPtr group = this->getViewGroup();
98  if (!group)
99  return;
100 
101  ViewGroupData::Options options = group->getOptions();
102  CameraStyleData data = options.mCameraStyle;
103 
104  mCameraViewAngle->setValue(data.mCameraViewAngle);
105  mCameraFollowTool->setValue(data.mCameraFollowTool);
106  mFocusFollowTool->setValue(data.mFocusFollowTool);
107  mCameraOnTooltip->setValue(data.mCameraLockToTooltip);
108  mCameraTooltipOffset->setValue(data.mCameraTooltipOffset);
109  mCameraNotBehindROI->setValue(data.mCameraNotBehindROI);
110  mTableLock->setValue(data.mTableLock);
111  mUniCam->setValue(data.mUniCam);
112  mElevation->setValue(data.mElevation);
113  mAutoZoomROI->setValue(data.mAutoZoomROI);
114  mFocusROI->setValue(data.mFocusROI);
115 }
116 
117 ViewGroupDataPtr ViewGroupPropertiesWidget::getViewGroup()
118 {
119  return mServices->view()->getGroup(mGroupIndex);
120 }
121 
122 void ViewGroupPropertiesWidget::createCameraStyleProperties()
123 {
124  StringPropertySelectDataPtr focusroi = StringPropertySelectData::New(mServices->patient());
125  focusroi->setValueName("Focus ROI");
126  focusroi->setHelp("Set focus to center of ROI");
127  focusroi->setTypeRegexp("roi");
128  mFocusROI = focusroi;
129  mCameraStyleProperties.push_back(mFocusROI);
130 
131  mCameraViewAngle = DoubleProperty::initialize("Angle of View", "",
132  "Camera View Angle, of Field of View",
133  30.0/180*M_PI, DoubleRange(10.0/180*M_PI, 150.0/180*M_PI, 1/180.0*M_PI), 0);
134  mCameraStyleProperties.push_back(mCameraViewAngle);
135  mCameraViewAngle->setInternal2Display(180.0/M_PI);
136 
137  mCameraFollowTool = BoolProperty::initialize("Camera Follow Tool", "",
138  "Camera position is fixed to the tool and moving along with it.\n"
139  "Zooming causes the position to slide along the tool axis",
140  true);
141  mCameraStyleProperties.push_back(mCameraFollowTool);
142 
143  mFocusFollowTool = BoolProperty::initialize("Focus Follow Tool", "",
144  "Scene focus is fixed to the tool and moving along with it.",
145  true);
146  mCameraStyleProperties.push_back(mFocusFollowTool);
147 
148  mCameraOnTooltip = BoolProperty::initialize("Camera on Tooltip", "",
149  "Camera position is located exactly on the tool tip",
150  true);
151  mCameraStyleProperties.push_back(mCameraOnTooltip);
152 
153  mCameraTooltipOffset = DoubleProperty::initialize("Camera Tooltip Offset", "",
154  "Camera offset from tooltip, used if Camera on Tooltip is set.",
155  0, DoubleRange(-100, 100, 1), 0);
156  mCameraStyleProperties.push_back(mCameraTooltipOffset);
157 
158  StringPropertySelectDataPtr notbehind = StringPropertySelectData::New(mServices->patient());
159  notbehind->setValueName("Camera not behind ROI");
160  notbehind->setHelp("Camera cannot move behind ROI");
161  notbehind->setTypeRegexp("roi");
162  mCameraNotBehindROI = notbehind;
163  mCameraStyleProperties.push_back(notbehind);
164 
165  mTableLock = BoolProperty::initialize("Table lock", "",
166  "The camera's up vector is aligned with the operating table's up vector.",
167  true);
168  mCameraStyleProperties.push_back(mTableLock);
169 
170  mElevation = DoubleProperty::initialize("Elevation", "",
171  "View angle above tool, used if Follow tool is set.",
172  0, DoubleRange(0, 80.0/180*M_PI, 5.0/180*M_PI), 0);
173  mElevation->setInternal2Display(180.0/M_PI);
174  mCameraStyleProperties.push_back(mElevation);
175 
176  mUniCam = BoolProperty::initialize("Unicam", "",
177  "Use the VTK Unicam interactor. Overrides other style settings",
178  true);
179  mCameraStyleProperties.push_back(mUniCam);
180 
181  StringPropertySelectDataPtr autozoom = StringPropertySelectData::New(mServices->patient());
182  autozoom->setValueName("Auto Zoom ROI");
183  autozoom->setHelp("Zoom so that the given ROI always is visible");
184  autozoom->setTypeRegexp("roi");
185  mAutoZoomROI = autozoom;
186  mCameraStyleProperties.push_back(mAutoZoomROI);
187 
188  for (unsigned i=0; i<mCameraStyleProperties.size(); ++i)
189  {
190  connect(mCameraStyleProperties[i].get(), &Property::changed,
191  this, &ViewGroupPropertiesWidget::onCameraStyleChanged);
192  }
193 }
194 
195 void ViewGroupPropertiesWidget::createCameraStyleWidget()
196 {
197  QGroupBox* groupBox = new QGroupBox("Camera Style");
198  mLayout->addWidget(groupBox);
199 
200  QVBoxLayout* layout = new QVBoxLayout(groupBox);
201  layout->setMargin(0);
202 
203  mCameraStyleInteractor.reset(new CameraStyleInteractor);
204  mCameraStyleInteractor->connectCameraStyle(this->getViewGroup());
205 
206  QToolBar* toolBar = new QToolBar(this);
207  layout->addWidget(toolBar);
208  toolBar->addActions(mCameraStyleInteractor->getInteractorStyleActionGroup()->actions());
209 
210 
211  QGridLayout *cameraStyleLayout = new QGridLayout;
212  layout->addLayout(cameraStyleLayout);
213  cameraStyleLayout->setMargin(0);
214  int count = 0;
215  for (unsigned i=0; i<mCameraStyleProperties.size(); ++i)
216  {
217  createDataWidget(mServices->view(), mServices->patient(), this, mCameraStyleProperties[i], cameraStyleLayout, count++);
218  }
219 }
220 
221 void ViewGroupPropertiesWidget::onCameraStyleChanged()
222 {
223  ViewGroupDataPtr group = this->getViewGroup();
224  ViewGroupData::Options options = group->getOptions();
225  CameraStyleData data = options.mCameraStyle;
226 
227  data.mCameraViewAngle = mCameraViewAngle->getValue();
228  data.mCameraFollowTool = mCameraFollowTool->getValue();
229  data.mFocusFollowTool = mFocusFollowTool->getValue();
230  data.mCameraLockToTooltip = mCameraOnTooltip->getValue();
231  data.mCameraTooltipOffset = mCameraTooltipOffset->getValue();
232  data.mCameraNotBehindROI = mCameraNotBehindROI->getValue();
233  data.mTableLock = mTableLock->getValue();
234  data.mUniCam = mUniCam->getValue();
235  data.mElevation = mElevation->getValue();
236  data.mAutoZoomROI = mAutoZoomROI->getValue();
237  data.mFocusROI = mFocusROI->getValue();
238 
239  options.mCameraStyle = data;
240  group->setOptions(options);
241 }
242 
243 
244 } // cx
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:50
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:61
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
Composite widget for string list selection.
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:109
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
boost::shared_ptr< class StringPropertySelectData > StringPropertySelectDataPtr
#define M_PI
Namespace for all CustusX production code.
ViewGroupPropertiesWidget(int groupIndex, VisServicesPtr services, QWidget *parent)