3 #include <QtConcurrent>
8 #include <QDesktopWidget>
10 #include <QApplication>
11 #include <QDesktopServices>
13 #include "boost/bind.hpp"
14 #include "boost/function.hpp"
46 this->createActions();
51 if (!mActions.count(uid))
52 CX_LOG_ERROR() << QString(
"Could not find action %1 in MainWindowActions object").arg(uid);
56 void MainWindowActions::createActions()
58 this->createAction(
"GotoDocumentation",
"Web Documentation",
59 QIcon(
":/icons/open_icon_library/applications-internet.png"),
61 &MainWindowActions::onGotoDocumentation);
63 this->createAction(
"StartLogConsole",
"Start Log Console",
65 QKeySequence(
"Ctrl+D"),
"Open Log Console as external application",
66 &MainWindowActions::onStartLogConsole);
68 this->createAction(
"ShootScreen",
"Shoot Screen",
69 QIcon(
":/icons/screenshot-screen.png"),
70 QKeySequence(
"Ctrl+f"),
"Save a screenshot to the patient folder.",
71 &MainWindowActions::shootScreen);
73 this->createAction(
"ShootWindow",
"Shoot Window",
74 QIcon(
":/icons/screenshot-window.png"),
75 QKeySequence(
"Ctrl+Shift+f"),
"Save an image of the application to the patient folder.",
76 &MainWindowActions::shootWindow);
78 mRecordFullscreenStreamingAction = this->createAction(
"RecordFullscreen",
"Record Fullscreen",
80 QKeySequence(
"F8"),
"Record a video of the full screen.",
81 &MainWindowActions::recordFullscreen);
83 this->updateRecordFullscreenActionSlot();
85 mShowPointPickerAction = this->createAction(
"ShowPointPicker",
"Point Picker",
86 QIcon(
":/icons/point_picker.png"),
87 QKeySequence(
""),
"Activate the 3D Point Picker Probe",
88 &MainWindowActions::togglePointPickerActionSlot);
89 mShowPointPickerAction->setCheckable(
true);
93 this->updatePointPickerActionSlot();
95 mStartStreamingAction = this->createAction(
"StartStreaming",
"Start Streaming",
96 QIcon(
":/icons/open_icon_library/.png"),
97 QKeySequence(
"Ctrl+V"),
"",
98 &MainWindowActions::toggleStreamingSlot);
100 this->updateStreamingActionSlot();
102 this->createAction(
"CenterToImageCenter",
"Center Image",
103 QIcon(
":/icons/center_image.png"),
105 &MainWindowActions::centerToImageCenterSlot);
107 this->createAction(
"CenterToTooltip",
"Center Tool",
108 QIcon(
":/icons/center_tool.png"),
109 QKeySequence(
""),
"",
110 &MainWindowActions::centerToTooltipSlot);
112 this->createPatientActions();
113 this->createTrackingActions();
116 void MainWindowActions::createTrackingActions()
118 this->createAction(
"ConfigureTools",
"Tool configuration",
119 QIcon(), QKeySequence(),
"",
120 &MainWindowActions::configureSlot);
123 this->createAction(
"InitializeTools",
"Initialize",
124 QIcon(), QKeySequence(),
"",
127 mTrackingToolsAction = this->createAction(
"TrackingTools",
"Start tracking",
128 QIcon(), QKeySequence(
"Ctrl+T"),
"",
129 &MainWindowActions::toggleTrackingSlot);
132 this->updateTrackingActionSlot();
135 void MainWindowActions::createPatientActions()
137 this->createAction(
"NewPatient",
"New Patient",
138 QIcon(
":/icons/open_icon_library/document-new-8.png"),
139 QKeySequence(
"Ctrl+N"),
140 "Create a new patient file",
141 &MainWindowActions::newPatientSlot);
143 this->createAction(
"SaveFile",
"Save Patient",
144 QIcon(
":/icons/open_icon_library/document-save-5.png"),
145 QKeySequence(
"Ctrl+S"),
147 &MainWindowActions::savePatientFileSlot);
149 this->createAction(
"LoadFile",
"Load Patient",
150 QIcon(
":/icons/open_icon_library/document-open-7.png"),
151 QKeySequence(
"Ctrl+L"),
153 &MainWindowActions::loadPatientFileSlot);
155 this->createAction(
"ClearPatient",
"Clear Patient",
158 "Clear the current patient from the application",
159 &MainWindowActions::clearPatientSlot);
161 this->createAction(
"ExportPatient",
"Export Patient",
164 "Export patient data to a folder",
165 &MainWindowActions::exportDataSlot);
167 this->createAction(
"ImportData",
"Import data",
168 QIcon(
":/icons/open_icon_library/document-import-2.png"),
169 QKeySequence(
"Ctrl+I"),
171 &MainWindowActions::importDataSlot);
175 QAction* MainWindowActions::createAction(QString uid, QString text, QIcon icon,
176 QKeySequence shortcut, QString help,
179 QAction* retval =
new QAction(icon, text,
this);
180 retval->setObjectName(uid);
181 retval->setShortcut(shortcut);
182 retval->setStatusTip(help);
183 connect(retval, &QAction::triggered,
this, triggerSlot);
184 mActions[uid] = retval;
190 QString timestampFormatFolderFriendly()
192 return QString(
"yyyy-MM-dd_hh-mm");
196 QWidget* MainWindowActions::parentWidget()
198 return dynamic_cast<QWidget*
>(this->parent());
202 void MainWindowActions::newPatientSlot()
204 QString patientDatafolder = this->getExistingSessionFolder();
206 QString timestamp = QDateTime::currentDateTime().toString(timestampFormatFolderFriendly());
207 QString filename = QString(
"%1_%2_%3.cx3")
210 .arg(
settings()->value(
"globalPatientNumber").toString());
212 QString choosenDir = patientDatafolder +
"/" + filename;
214 QFileDialog dialog(this->parentWidget(), tr(
"Select directory to save patient in"), patientDatafolder +
"/");
215 dialog.setOption(QFileDialog::DontUseNativeDialog,
true);
216 dialog.setOption(QFileDialog::ShowDirsOnly,
true);
217 dialog.selectFile(filename);
220 choosenDir = dialog.selectedFiles().front();
222 if (!choosenDir.endsWith(
".cx3"))
223 choosenDir += QString(
".cx3");
226 int patientNumber =
settings()->
value(
"globalPatientNumber").toInt();
229 mServices->session()->load(choosenDir);
232 QString MainWindowActions::getExistingSessionFolder()
234 return profile()->getSessionRootFolder();
237 void MainWindowActions::clearPatientSlot()
239 mServices->session()->clear();
242 void MainWindowActions::savePatientFileSlot()
246 reportWarning(
"No patient selected, select or create patient before saving!");
247 this->newPatientSlot();
251 mServices->session()->save();
254 void MainWindowActions::loadPatientFileSlot()
256 QString patientDatafolder = this->getExistingSessionFolder();
259 QString folder = QFileDialog::getExistingDirectory(this->parentWidget(),
"Select patient", patientDatafolder, QFileDialog::ShowDirsOnly);
260 if (folder.isEmpty())
263 mServices->session()->load(folder);
266 void MainWindowActions::exportDataSlot()
268 this->savePatientFileSlot();
270 ExportDataDialog* wizard =
new ExportDataDialog(mServices->patient(), this->parentWidget());
274 void MainWindowActions::importDataSlot()
276 this->savePatientFileSlot();
278 QString folder = mLastImportDataFolder;
279 if (folder.isEmpty())
280 folder =
profile()->getSessionRootFolder();
282 QStringList fileName = QFileDialog::getOpenFileNames(this->parentWidget(), QString(tr(
"Select data file(s) for import")),
283 folder, tr(
"Image/Mesh (*.mhd *.mha *.stl *.vtk *.mnc *.png)"));
284 if (fileName.empty())
286 report(
"Import canceled");
290 mLastImportDataFolder = QFileInfo(fileName[0]).absolutePath();
292 for (
int i=0; i<fileName.size(); ++i)
294 ImportDataDialog* wizard =
new ImportDataDialog(mServices->patient(), fileName[i], this->parentWidget());
299 void MainWindowActions::shootScreen()
301 mScreenShotWriter->grabAllScreensToFile();
304 void MainWindowActions::shootWindow()
309 while (mServices->view()->getLayoutWidget(index))
310 this->shootOneLayout(index++);
313 void MainWindowActions::shootOneLayout(
int index)
315 QWidget* widget = mServices->view()->getLayoutWidget(index);
316 ViewCollectionWidget* vcWidget =
dynamic_cast<ViewCollectionWidget*
>(widget);
318 ViewCollectionImageWriter grabber(vcWidget);
320 mScreenShotWriter->save(pm, QString(
"_layout%1").arg(index));
323 void MainWindowActions::recordFullscreen()
325 QString path =
patientService()->generateFilePath(
"Screenshots",
"mp4");
327 if(
vlc()->isRecording())
333 void MainWindowActions::updateRecordFullscreenActionSlot()
335 mRecordFullscreenStreamingAction->setCheckable(
true);
336 mRecordFullscreenStreamingAction->blockSignals(
true);
337 mRecordFullscreenStreamingAction->setChecked(
vlc()->isRecording());
338 mRecordFullscreenStreamingAction->blockSignals(
false);
340 if(
vlc()->isRecording())
342 mRecordFullscreenStreamingAction->setIcon(QIcon(
":/icons/Video-icon_green.png"));
346 mRecordFullscreenStreamingAction->setIcon(QIcon(
":/icons/Video-icon_gray.png"));
351 void MainWindowActions::onStartLogConsole()
355 mLocalVideoServerProcess.reset(
new ProcessWrapper(QString(
"LogConsole")));
356 mLocalVideoServerProcess->launchWithRelativePath(fullname, QStringList());
359 void MainWindowActions::toggleStreamingSlot()
367 void MainWindowActions::updateStreamingActionSlot()
371 mStartStreamingAction->setIcon(QIcon(
":/icons/streaming_green.png"));
372 mStartStreamingAction->setText(
"Stop Streaming");
376 mStartStreamingAction->setIcon(QIcon(
":/icons/streaming_red.png"));
377 mStartStreamingAction->setText(
"Start Streaming");
381 void MainWindowActions::centerToImageCenterSlot()
383 viewService()->centerToImageCenterInActiveViewGroup();
386 void MainWindowActions::centerToTooltipSlot()
389 nav->centerToTooltip();
392 void MainWindowActions::togglePointPickerActionSlot()
395 ViewGroupData::Options options = data->getOptions();
396 options.mShowPointPickerProbe = !options.mShowPointPickerProbe;
397 data->setOptions(options);
399 void MainWindowActions::updatePointPickerActionSlot()
403 bool show =
viewService()->getGroup(0)->getOptions().mShowPointPickerProbe;
404 mShowPointPickerAction->setChecked(show);
407 void MainWindowActions::updateTrackingActionSlot()
411 mTrackingToolsAction->setIcon(QIcon(
":/icons/polaris-green.png"));
412 mTrackingToolsAction->setText(
"Stop Tracking");
416 mTrackingToolsAction->setIcon(QIcon(
":/icons/polaris-red.png"));
417 mTrackingToolsAction->setText(
"Start Tracking");
421 void MainWindowActions::configureSlot()
426 void MainWindowActions::toggleTrackingSlot()
434 void MainWindowActions::onGotoDocumentation()
437 QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
cxResource_EXPORT ProfilePtr profile()
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
boost::shared_ptr< class VisServices > VisServicesPtr
static QString getWebsiteUserDocumentationURL()
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void startRecording(QString saveFile)
boost::shared_ptr< class Navigation > NavigationPtr
void setValue(const QString &key, const QVariant &value)
static QImage vtkImageData2QImage(vtkImageDataPtr input)
void reportWarning(QString msg)
MainWindowActions(VisServicesPtr services, QWidget *parent)
virtual void setState(const Tool::State val)=0
Settings * settings()
Shortcut for accessing the settings instance.
QAction * getAction(QString uid)
cxLogicManager_EXPORT ViewServicePtr viewService()
cxLogicManager_EXPORT VideoServicePtr videoService()
static QString findExecutableInStandardLocations(QString filename)
look for an exe in the same folder as the executable or bundle.
cxLogicManager_EXPORT PatientModelServicePtr patientService()
cxLogicManager_EXPORT TrackingServicePtr trackingService()
VLCRecorder * vlc()
Shortcut for accessing the vlc recorder.