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->setShortcut(shortcut);
181 retval->setStatusTip(help);
182 connect(retval, &QAction::triggered,
this, triggerSlot);
183 mActions[uid] = retval;
189 QString timestampFormatFolderFriendly()
191 return QString(
"yyyy-MM-dd_hh-mm");
195 QWidget* MainWindowActions::parentWidget()
197 return dynamic_cast<QWidget*
>(this->parent());
201 void MainWindowActions::newPatientSlot()
203 QString patientDatafolder = this->getExistingSessionFolder();
205 QString timestamp = QDateTime::currentDateTime().toString(timestampFormatFolderFriendly());
206 QString filename = QString(
"%1_%2_%3.cx3")
209 .arg(
settings()->value(
"globalPatientNumber").toString());
211 QString choosenDir = patientDatafolder +
"/" + filename;
213 QFileDialog dialog(this->parentWidget(), tr(
"Select directory to save patient in"), patientDatafolder +
"/");
214 dialog.setOption(QFileDialog::DontUseNativeDialog,
true);
215 dialog.setOption(QFileDialog::ShowDirsOnly,
true);
216 dialog.selectFile(filename);
219 choosenDir = dialog.selectedFiles().front();
221 if (!choosenDir.endsWith(
".cx3"))
222 choosenDir += QString(
".cx3");
225 int patientNumber =
settings()->
value(
"globalPatientNumber").toInt();
228 mServices->session()->load(choosenDir);
231 QString MainWindowActions::getExistingSessionFolder()
233 return profile()->getSessionRootFolder();
236 void MainWindowActions::clearPatientSlot()
238 mServices->session()->clear();
241 void MainWindowActions::savePatientFileSlot()
245 reportWarning(
"No patient selected, select or create patient before saving!");
246 this->newPatientSlot();
250 mServices->session()->save();
253 void MainWindowActions::loadPatientFileSlot()
255 QString patientDatafolder = this->getExistingSessionFolder();
258 QString folder = QFileDialog::getExistingDirectory(this->parentWidget(),
"Select patient", patientDatafolder, QFileDialog::ShowDirsOnly);
259 if (folder.isEmpty())
262 mServices->session()->load(folder);
265 void MainWindowActions::exportDataSlot()
267 this->savePatientFileSlot();
269 ExportDataDialog* wizard =
new ExportDataDialog(mServices->patient(), this->parentWidget());
273 void MainWindowActions::importDataSlot()
275 this->savePatientFileSlot();
277 QString folder = mLastImportDataFolder;
278 if (folder.isEmpty())
279 folder =
profile()->getSessionRootFolder();
281 QStringList fileName = QFileDialog::getOpenFileNames(this->parentWidget(), QString(tr(
"Select data file(s) for import")),
282 folder, tr(
"Image/Mesh (*.mhd *.mha *.stl *.vtk *.mnc *.png)"));
283 if (fileName.empty())
285 report(
"Import canceled");
289 mLastImportDataFolder = QFileInfo(fileName[0]).absolutePath();
291 for (
int i=0; i<fileName.size(); ++i)
293 ImportDataDialog* wizard =
new ImportDataDialog(mServices->patient(), fileName[i], this->parentWidget());
298 void MainWindowActions::shootScreen()
300 mScreenShotWriter->grabAllScreensToFile();
303 void MainWindowActions::shootWindow()
308 while (mServices->view()->getLayoutWidget(index))
309 this->shootOneLayout(index++);
312 void MainWindowActions::shootOneLayout(
int index)
314 QWidget* widget = mServices->view()->getLayoutWidget(index);
315 ViewCollectionWidget* vcWidget =
dynamic_cast<ViewCollectionWidget*
>(widget);
317 ViewCollectionImageWriter grabber(vcWidget);
319 mScreenShotWriter->save(pm, QString(
"_layout%1").arg(index));
322 void MainWindowActions::recordFullscreen()
324 QString path =
patientService()->generateFilePath(
"Screenshots",
"mp4");
326 if(
vlc()->isRecording())
332 void MainWindowActions::updateRecordFullscreenActionSlot()
334 mRecordFullscreenStreamingAction->setCheckable(
true);
335 mRecordFullscreenStreamingAction->blockSignals(
true);
336 mRecordFullscreenStreamingAction->setChecked(
vlc()->isRecording());
337 mRecordFullscreenStreamingAction->blockSignals(
false);
339 if(
vlc()->isRecording())
341 mRecordFullscreenStreamingAction->setIcon(QIcon(
":/icons/Video-icon_green.png"));
345 mRecordFullscreenStreamingAction->setIcon(QIcon(
":/icons/Video-icon_gray.png"));
350 void MainWindowActions::onStartLogConsole()
354 mLocalVideoServerProcess.reset(
new ProcessWrapper(QString(
"LogConsole")));
355 mLocalVideoServerProcess->launchWithRelativePath(fullname, QStringList());
358 void MainWindowActions::toggleStreamingSlot()
366 void MainWindowActions::updateStreamingActionSlot()
370 mStartStreamingAction->setIcon(QIcon(
":/icons/streaming_green.png"));
371 mStartStreamingAction->setText(
"Stop Streaming");
375 mStartStreamingAction->setIcon(QIcon(
":/icons/streaming_red.png"));
376 mStartStreamingAction->setText(
"Start Streaming");
380 void MainWindowActions::centerToImageCenterSlot()
382 viewService()->centerToImageCenterInActiveViewGroup();
385 void MainWindowActions::centerToTooltipSlot()
388 nav->centerToTooltip();
391 void MainWindowActions::togglePointPickerActionSlot()
394 ViewGroupData::Options options = data->getOptions();
395 options.mShowPointPickerProbe = !options.mShowPointPickerProbe;
396 data->setOptions(options);
398 void MainWindowActions::updatePointPickerActionSlot()
402 bool show =
viewService()->getGroup(0)->getOptions().mShowPointPickerProbe;
403 mShowPointPickerAction->setChecked(show);
406 void MainWindowActions::updateTrackingActionSlot()
410 mTrackingToolsAction->setIcon(QIcon(
":/icons/polaris-green.png"));
411 mTrackingToolsAction->setText(
"Stop Tracking");
415 mTrackingToolsAction->setIcon(QIcon(
":/icons/polaris-red.png"));
416 mTrackingToolsAction->setText(
"Start Tracking");
420 void MainWindowActions::configureSlot()
425 void MainWindowActions::toggleTrackingSlot()
433 void MainWindowActions::onGotoDocumentation()
436 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.