Fraxinus  18.10
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 #include <QLabel>
14 #include <QGroupBox>
15 #include <QToolBar>
17 #include "cxViewService.h"
18 #include "cxViewGroupData.h"
19 #include "cxStringProperty.h"
20 #include "cxBoolProperty.h"
21 #include "cxVisServices.h"
22 #include "cxHelperWidgets.h"
23 #include "cxLogger.h"
26 
27 namespace cx
28 {
29 
31  VisServicesPtr services,
32  QWidget* parent) :
33  BaseWidget(parent, "ViewGroupPropertiesWidget", "View Properties"),
34  mGroupIndex(groupIndex),
35  mServices(services)
36 {
37  ViewGroupDataPtr group = this->getViewGroup();
39 
40  mLayout = new QVBoxLayout(this);
41  this->setModified();
42 }
43 
45 {
46 }
47 
49 {
50  if (mLayout->count()) // already created
51  return;
52 
53  ViewGroupDataPtr group = this->getViewGroup();
54  if (!group)
55  return;
56 
57  mLayout->setMargin(2);
58 
59  StringListSelectWidget* slices3D = new StringListSelectWidget(this, group->getSliceDefinitionProperty());
60  mLayout->addWidget(slices3D);
61 
62  this->createCameraStyleProperties();
63  this->createCameraStyleWidget();
64 
65  mLayout->addStretch();
66 }
67 
69 {
70  this->setupUI();
71  this->updateFrontend();
72 }
73 
74 void ViewGroupPropertiesWidget::updateFrontend()
75 {
76  ViewGroupDataPtr group = this->getViewGroup();
77  if (!group)
78  return;
79 
80  ViewGroupData::Options options = group->getOptions();
81  CameraStyleData data = options.mCameraStyle;
82 
83  mCameraViewAngle->setValue(data.mCameraViewAngle);
84  mCameraFollowTool->setValue(data.mCameraFollowTool);
85  mFocusFollowTool->setValue(data.mFocusFollowTool);
86  mCameraOnTooltip->setValue(data.mCameraLockToTooltip);
87  mCameraTooltipOffset->setValue(data.mCameraTooltipOffset);
88  mCameraNotBehindROI->setValue(data.mCameraNotBehindROI);
89  mTableLock->setValue(data.mTableLock);
90  mUniCam->setValue(data.mUniCam);
91  mElevation->setValue(data.mElevation);
92  mAutoZoomROI->setValue(data.mAutoZoomROI);
93  mFocusROI->setValue(data.mFocusROI);
94 }
95 
96 ViewGroupDataPtr ViewGroupPropertiesWidget::getViewGroup()
97 {
98  return mServices->view()->getGroup(mGroupIndex);
99 }
100 
101 void ViewGroupPropertiesWidget::createCameraStyleProperties()
102 {
103  StringPropertySelectDataPtr focusroi = StringPropertySelectData::New(mServices->patient());
104  focusroi->setValueName("Focus ROI");
105  focusroi->setHelp("Set focus to center of ROI");
106  focusroi->setTypeRegexp("roi");
107  mFocusROI = focusroi;
108  mCameraStyleProperties.push_back(mFocusROI);
109 
110  mCameraViewAngle = DoubleProperty::initialize("Angle of View", "",
111  "Camera View Angle, of Field of View",
112  30.0/180*M_PI, DoubleRange(10.0/180*M_PI, 150.0/180*M_PI, 1/180.0*M_PI), 0);
113  mCameraStyleProperties.push_back(mCameraViewAngle);
114  mCameraViewAngle->setInternal2Display(180.0/M_PI);
115 
116  mCameraFollowTool = BoolProperty::initialize("Camera Follow Tool", "",
117  "Camera position is fixed to the tool and moving along with it.\n"
118  "Zooming causes the position to slide along the tool axis",
119  true);
120  mCameraStyleProperties.push_back(mCameraFollowTool);
121 
122  mFocusFollowTool = BoolProperty::initialize("Focus Follow Tool", "",
123  "Scene focus is fixed to the tool and moving along with it.",
124  true);
125  mCameraStyleProperties.push_back(mFocusFollowTool);
126 
127  mCameraOnTooltip = BoolProperty::initialize("Camera on Tooltip", "",
128  "Camera position is located exactly on the tool tip",
129  true);
130  mCameraStyleProperties.push_back(mCameraOnTooltip);
131 
132  mCameraTooltipOffset = DoubleProperty::initialize("Camera Tooltip Offset", "",
133  "Camera offset from tooltip, used if Camera on Tooltip is set.",
134  0, DoubleRange(-100, 100, 1), 0);
135  mCameraStyleProperties.push_back(mCameraTooltipOffset);
136 
137  StringPropertySelectDataPtr notbehind = StringPropertySelectData::New(mServices->patient());
138  notbehind->setValueName("Camera not behind ROI");
139  notbehind->setHelp("Camera cannot move behind ROI");
140  notbehind->setTypeRegexp("roi");
141  mCameraNotBehindROI = notbehind;
142  mCameraStyleProperties.push_back(notbehind);
143 
144  mTableLock = BoolProperty::initialize("Table lock", "",
145  "The camera's up vector is aligned with the operating table's up vector.",
146  true);
147  mCameraStyleProperties.push_back(mTableLock);
148 
149  mElevation = DoubleProperty::initialize("Elevation", "",
150  "View angle above tool, used if Follow tool is set.",
151  0, DoubleRange(0, 80.0/180*M_PI, 5.0/180*M_PI), 0);
152  mElevation->setInternal2Display(180.0/M_PI);
153  mCameraStyleProperties.push_back(mElevation);
154 
155  mUniCam = BoolProperty::initialize("Unicam", "",
156  "Use the VTK Unicam interactor. Overrides other style settings",
157  true);
158  mCameraStyleProperties.push_back(mUniCam);
159 
160  StringPropertySelectDataPtr autozoom = StringPropertySelectData::New(mServices->patient());
161  autozoom->setValueName("Auto Zoom ROI");
162  autozoom->setHelp("Zoom so that the given ROI always is visible");
163  autozoom->setTypeRegexp("roi");
164  mAutoZoomROI = autozoom;
165  mCameraStyleProperties.push_back(mAutoZoomROI);
166 
167  for (unsigned i=0; i<mCameraStyleProperties.size(); ++i)
168  {
169  connect(mCameraStyleProperties[i].get(), &Property::changed,
170  this, &ViewGroupPropertiesWidget::onCameraStyleChanged);
171  }
172 }
173 
174 void ViewGroupPropertiesWidget::createCameraStyleWidget()
175 {
176  QGroupBox* groupBox = new QGroupBox("Camera Style");
177  mLayout->addWidget(groupBox);
178 
179  QVBoxLayout* layout = new QVBoxLayout(groupBox);
180  layout->setMargin(0);
181 
182  mCameraStyleInteractor.reset(new CameraStyleInteractor);
183  mCameraStyleInteractor->connectCameraStyle(this->getViewGroup());
184 
185  QToolBar* toolBar = new QToolBar(this);
186  layout->addWidget(toolBar);
187  toolBar->addActions(mCameraStyleInteractor->getInteractorStyleActionGroup()->actions());
188 
189 
190  QGridLayout *cameraStyleLayout = new QGridLayout;
191  layout->addLayout(cameraStyleLayout);
192  cameraStyleLayout->setMargin(0);
193  int count = 0;
194  for (unsigned i=0; i<mCameraStyleProperties.size(); ++i)
195  {
196  createDataWidget(mServices->view(), mServices->patient(), this, mCameraStyleProperties[i], cameraStyleLayout, count++);
197  }
198 }
199 
200 void ViewGroupPropertiesWidget::onCameraStyleChanged()
201 {
202  ViewGroupDataPtr group = this->getViewGroup();
203  ViewGroupData::Options options = group->getOptions();
204  CameraStyleData data = options.mCameraStyle;
205 
206  data.mCameraViewAngle = mCameraViewAngle->getValue();
207  data.mCameraFollowTool = mCameraFollowTool->getValue();
208  data.mFocusFollowTool = mFocusFollowTool->getValue();
209  data.mCameraLockToTooltip = mCameraOnTooltip->getValue();
210  data.mCameraTooltipOffset = mCameraTooltipOffset->getValue();
211  data.mCameraNotBehindROI = mCameraNotBehindROI->getValue();
212  data.mTableLock = mTableLock->getValue();
213  data.mUniCam = mUniCam->getValue();
214  data.mElevation = mElevation->getValue();
215  data.mAutoZoomROI = mAutoZoomROI->getValue();
216  data.mFocusROI = mFocusROI->getValue();
217 
218  options.mCameraStyle = data;
219  group->setOptions(options);
220 }
221 
222 
223 } // 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:29
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
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:88
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)