NorMIT-nav  2023.01.05-dev+develop.0da12
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"
27 #include "cxTool.h"
28 
29 namespace cx
30 {
31 
33  VisServicesPtr services,
34  QWidget* parent) :
35  BaseWidget(parent, "ViewGroupPropertiesWidget", "View Properties"),
36  mGroupIndex(groupIndex),
37  mServices(services)
38 {
39  ViewGroupDataPtr group = this->getViewGroup();
41 
42  mLayout = new QVBoxLayout(this);
43  this->setModified();
44 
45  mToolSelector = StringPropertySelectTool::New(mServices->tracking());
47 }
48 
50 {
51  disconnect(mToolSelector.get(), &StringPropertySelectTool::changed, this, &ViewGroupPropertiesWidget::onToolChanged);
52 }
53 
55 {
56  if (mLayout->count()) // already created
57  return;
58 
59  ViewGroupDataPtr group = this->getViewGroup();
60  if (!group)
61  return;
62 
63  mLayout->setMargin(2);
64 
65  StringListSelectWidget* slices3D = new StringListSelectWidget(this, group->getSliceDefinitionProperty());
66  mLayout->addWidget(slices3D);
67 
68  this->createCameraStyleProperties();
69  this->createCameraStyleWidget();
70  this->createControllingToolSelector();
71 
72  mLayout->addStretch();
73 }
74 
76 {
77  this->setupUI();
78  this->updateFrontend();
79 }
80 
81 void ViewGroupPropertiesWidget::updateFrontend()
82 {
83  ViewGroupDataPtr group = this->getViewGroup();
84  if (!group)
85  return;
86 
87  ViewGroupData::Options options = group->getOptions();
88  CameraStyleData data = options.mCameraStyle;
89 
90  mCameraViewAngle->setValue(data.mCameraViewAngle);
91  mCameraFollowTool->setValue(data.mCameraFollowTool);
92  mFocusFollowTool->setValue(data.mFocusFollowTool);
93  mCameraOnTooltip->setValue(data.mCameraLockToTooltip);
94  mCameraTooltipOffset->setValue(data.mCameraTooltipOffset);
95  mCameraNotBehindROI->setValue(data.mCameraNotBehindROI);
96  mTableLock->setValue(data.mTableLock);
97  mUniCam->setValue(data.mUniCam);
98  mElevation->setValue(data.mElevation);
99  mAutoZoomROI->setValue(data.mAutoZoomROI);
100  mFocusROI->setValue(data.mFocusROI);
101 
102  ToolPtr tool = group->getControllingTool();
103  if(tool)
104  mToolSelector->setValue(tool->getUid());
105 }
106 
107 ViewGroupDataPtr ViewGroupPropertiesWidget::getViewGroup()
108 {
109  return mServices->view()->getGroup(mGroupIndex);
110 }
111 
112 void ViewGroupPropertiesWidget::createCameraStyleProperties()
113 {
114  StringPropertySelectDataPtr focusroi = StringPropertySelectData::New(mServices->patient());
115  focusroi->setValueName("Focus ROI");
116  focusroi->setHelp("Set focus to center of ROI");
117  focusroi->setTypeRegexp("roi");
118  mFocusROI = focusroi;
119  mCameraStyleProperties.push_back(mFocusROI);
120 
121  mCameraViewAngle = DoubleProperty::initialize("Angle of View", "",
122  "Camera View Angle, of Field of View",
123  30.0/180*M_PI, DoubleRange(10.0/180*M_PI, 150.0/180*M_PI, 1/180.0*M_PI), 0);
124  mCameraStyleProperties.push_back(mCameraViewAngle);
125  mCameraViewAngle->setInternal2Display(180.0/M_PI);
126 
127  mCameraFollowTool = BoolProperty::initialize("Camera Follow Tool", "",
128  "Camera position is fixed to the tool and moving along with it.\n"
129  "Zooming causes the position to slide along the tool axis",
130  true);
131  mCameraStyleProperties.push_back(mCameraFollowTool);
132 
133  mFocusFollowTool = BoolProperty::initialize("Focus Follow Tool", "",
134  "Scene focus is fixed to the tool and moving along with it.",
135  true);
136  mCameraStyleProperties.push_back(mFocusFollowTool);
137 
138  mCameraOnTooltip = BoolProperty::initialize("Camera on Tooltip", "",
139  "Camera position is located exactly on the tool tip",
140  true);
141  mCameraStyleProperties.push_back(mCameraOnTooltip);
142 
143  mCameraTooltipOffset = DoubleProperty::initialize("Camera Tooltip Offset", "",
144  "Camera offset from tooltip, used if Camera on Tooltip is set.",
145  0, DoubleRange(-100, 100, 1), 0);
146  mCameraStyleProperties.push_back(mCameraTooltipOffset);
147 
148  StringPropertySelectDataPtr notbehind = StringPropertySelectData::New(mServices->patient());
149  notbehind->setValueName("Camera not behind ROI");
150  notbehind->setHelp("Camera cannot move behind ROI");
151  notbehind->setTypeRegexp("roi");
152  mCameraNotBehindROI = notbehind;
153  mCameraStyleProperties.push_back(notbehind);
154 
155  mTableLock = BoolProperty::initialize("Table lock", "",
156  "The camera's up vector is aligned with the operating table's up vector.",
157  true);
158  mCameraStyleProperties.push_back(mTableLock);
159 
160  mElevation = DoubleProperty::initialize("Elevation", "",
161  "View angle above tool, used if Follow tool is set.",
162  0, DoubleRange(0, 80.0/180*M_PI, 5.0/180*M_PI), 0);
163  mElevation->setInternal2Display(180.0/M_PI);
164  mCameraStyleProperties.push_back(mElevation);
165 
166  mUniCam = BoolProperty::initialize("Unicam", "",
167  "Use the VTK Unicam interactor. Overrides other style settings",
168  true);
169  mCameraStyleProperties.push_back(mUniCam);
170 
171  StringPropertySelectDataPtr autozoom = StringPropertySelectData::New(mServices->patient());
172  autozoom->setValueName("Auto Zoom ROI");
173  autozoom->setHelp("Zoom so that the given ROI always is visible");
174  autozoom->setTypeRegexp("roi");
175  mAutoZoomROI = autozoom;
176  mCameraStyleProperties.push_back(mAutoZoomROI);
177 
178  for (unsigned i=0; i<mCameraStyleProperties.size(); ++i)
179  {
180  connect(mCameraStyleProperties[i].get(), &Property::changed,
181  this, &ViewGroupPropertiesWidget::onCameraStyleChanged);
182  }
183 }
184 
185 void ViewGroupPropertiesWidget::createCameraStyleWidget()
186 {
187  QGroupBox* groupBox = new QGroupBox("Camera Style");
188  mLayout->addWidget(groupBox);
189 
190  QVBoxLayout* layout = new QVBoxLayout(groupBox);
191  layout->setMargin(0);
192 
193  mCameraStyleInteractor.reset(new CameraStyleInteractor);
194  mCameraStyleInteractor->connectCameraStyle(this->getViewGroup());
195 
196  QToolBar* toolBar = new QToolBar(this);
197  layout->addWidget(toolBar);
198  toolBar->addActions(mCameraStyleInteractor->getInteractorStyleActionGroup()->actions());
199 
200 
201  QGridLayout *cameraStyleLayout = new QGridLayout;
202  layout->addLayout(cameraStyleLayout);
203  cameraStyleLayout->setMargin(0);
204  int count = 0;
205  for (unsigned i=0; i<mCameraStyleProperties.size(); ++i)
206  {
207  createDataWidget(mServices->view(), mServices->patient(), this, mCameraStyleProperties[i], cameraStyleLayout, count++);
208  }
209 }
210 
211 void ViewGroupPropertiesWidget::createControllingToolSelector()
212 {
213  mToolSelector->setValueName("Controlling Tool");
214  mToolSelector->setHelp("Select a tool for controlling the 2D/3D views in this view group. This will override the Active Tool");
215  mToolSelector->provideActiveTool(true);
216  mToolSelector->setActiveTool();
217 
218  LabeledComboBoxWidget* toolSelectorWidget = new LabeledComboBoxWidget(this, mToolSelector);
219 
220  QHBoxLayout *layout = new QHBoxLayout();
221  layout->addWidget(toolSelectorWidget);
222  mLayout->addLayout(layout);
223 }
224 
226 {
227  ToolPtr tool = mToolSelector->getTool();
228  ViewGroupDataPtr group = this->getViewGroup();
229 
230  // If active tool is selected, clear controlling tool.
231  // This is done to make sure we don't lock to a specific tool, as active tool can change.
232  if(mToolSelector->isActiveToolSelected())
233  tool.reset();
234 
235  //if(tool)
236  // CX_LOG_DEBUG() << "Changing controlling tool: " << tool->getName();
237  //else
238  // CX_LOG_DEBUG() << "Clear controlling tool value. Active tool will be used";
239 
240  group->setControllingTool(tool);
241 }
242 
243 void ViewGroupPropertiesWidget::onCameraStyleChanged()
244 {
245  ViewGroupDataPtr group = this->getViewGroup();
246  ViewGroupData::Options options = group->getOptions();
247  CameraStyleData data = options.mCameraStyle;
248 
249  data.mCameraViewAngle = mCameraViewAngle->getValue();
250  data.mCameraFollowTool = mCameraFollowTool->getValue();
251  data.mFocusFollowTool = mFocusFollowTool->getValue();
252  data.mCameraLockToTooltip = mCameraOnTooltip->getValue();
253  data.mCameraTooltipOffset = mCameraTooltipOffset->getValue();
254  data.mCameraNotBehindROI = mCameraNotBehindROI->getValue();
255  data.mTableLock = mTableLock->getValue();
256  data.mUniCam = mUniCam->getValue();
257  data.mElevation = mElevation->getValue();
258  data.mAutoZoomROI = mAutoZoomROI->getValue();
259  data.mFocusROI = mFocusROI->getValue();
260 
261  options.mCameraStyle = data;
262  group->setOptions(options);
263 }
264 
265 } // cx
cx::BoolProperty::initialize
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
Definition: cxBoolProperty.cpp:30
cx::CameraStyleData::mElevation
double mElevation
Definition: cxViewGroupData.h:57
cx::createDataWidget
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
Definition: cxHelperWidgets.cpp:41
cx::StringPropertySelectData::New
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
Definition: cxSelectDataStringProperty.h:101
cxLogger.h
cx::ViewGroupDataPtr
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:29
cx::CameraStyleData::mUniCam
bool mUniCam
Definition: cxViewGroupData.h:58
cx::OptimizedUpdateWidget::setModified
virtual void setModified()
Definition: cxOptimizedUpdateWidget.cpp:36
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::ViewGroupPropertiesWidget::~ViewGroupPropertiesWidget
virtual ~ViewGroupPropertiesWidget()
Definition: cxViewGroupPropertiesWidget.cpp:49
cx::CameraStyleData::mAutoZoomROI
QString mAutoZoomROI
Definition: cxViewGroupData.h:61
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cx::CameraStyleData::mTableLock
bool mTableLock
Definition: cxViewGroupData.h:56
cx::CameraStyleData::mCameraTooltipOffset
double mCameraTooltipOffset
Definition: cxViewGroupData.h:55
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cxLabeledComboBoxWidget.h
cx::CameraStyleData::mFocusFollowTool
bool mFocusFollowTool
Definition: cxViewGroupData.h:53
cx::CameraStyleData::mCameraViewAngle
double mCameraViewAngle
Definition: cxViewGroupData.h:51
cxViewGroupData.h
cx::ViewGroupData::Options::mCameraStyle
CameraStyleData mCameraStyle
Definition: cxViewGroupData.h:151
cx::ViewGroupPropertiesWidget::ViewGroupPropertiesWidget
ViewGroupPropertiesWidget(int groupIndex, VisServicesPtr services, QWidget *parent)
Definition: cxViewGroupPropertiesWidget.cpp:32
cx::ViewGroupPropertiesWidget::setupUI
void setupUI()
Definition: cxViewGroupPropertiesWidget.cpp:54
cx::ViewGroupData::optionsChanged
void optionsChanged()
cxHelperWidgets.h
cx::DoubleProperty::initialize
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
Definition: cxDoubleProperty.cpp:30
cx::ViewGroupData::Options
Definition: cxViewGroupData.h:145
cxViewService.h
cx::CameraStyleData::mCameraLockToTooltip
bool mCameraLockToTooltip
Definition: cxViewGroupData.h:54
cxTool.h
cx::CameraStyleData::mFocusROI
QString mFocusROI
Definition: cxViewGroupData.h:60
cx::CameraStyleData
Definition: cxViewGroupData.h:41
cxStringListSelectWidget.h
cx::ViewGroupPropertiesWidget::onToolChanged
void onToolChanged()
Definition: cxViewGroupPropertiesWidget.cpp:225
M_PI
#define M_PI
Definition: cxReconstructParams.cpp:25
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::StringListSelectWidget
Composite widget for string list selection.
Definition: cxStringListSelectWidget.h:33
cx::StringPropertySelectTool::New
static StringPropertySelectToolPtr New(TrackingServicePtr trackingService)
Definition: cxStringPropertySelectTool.h:40
cx::ViewGroupPropertiesWidget::prePaintEvent
virtual void prePaintEvent()
Definition: cxViewGroupPropertiesWidget.cpp:75
cxStringProperty.h
cxSelectDataStringProperty.h
cxViewGroupPropertiesWidget.h
cxBoolProperty.h
cx::StringPropertySelectDataPtr
boost::shared_ptr< class StringPropertySelectData > StringPropertySelectDataPtr
Definition: cxClippingWidget.h:23
cx::CameraStyleData::mCameraNotBehindROI
QString mCameraNotBehindROI
Definition: cxViewGroupData.h:59
cx::CameraStyleData::mCameraFollowTool
bool mCameraFollowTool
Definition: cxViewGroupData.h:52
cxCameraStyleInteractor.h
cxVisServices.h