14 #include <QHBoxLayout> 15 #include <QVBoxLayout> 16 #include <QPushButton> 20 #include <QFileDialog> 21 #include <QSpacerItem> 35 #define START_TEXT "Start PlusServer and connect tracking and streaming" 36 #define STOP_TEXT "Stop PlusServer and disconnect tracking and streaming" 41 BaseWidget(parent,
"plus_connect_widget" ,
"Connect to PlusServer"),
45 mFilePreviewWidget(NULL),
46 mPlusPathComboBox(NULL)
48 QVBoxLayout* toplayout =
new QVBoxLayout(
this);
50 QGridLayout* layout =
new QGridLayout();
51 toplayout->addLayout(layout);
57 if(!QFile::exists(mPlusPath))
58 this->searchForPlus();
60 QLabel* plusPathLabel =
new QLabel(tr(
"PlusServer path:"));
61 mPlusPathComboBox =
new QComboBox();
62 mPlusPathComboBox->addItem(mPlusPath);
63 QAction* browsePlusPathAction =
new QAction(QIcon(
":/icons/open.png"), tr(
"Browse for PlusServer..."),
this);
64 connect(browsePlusPathAction, &QAction::triggered,
this, &PlusConnectWidget::browsePlusPathSlot);
65 QToolButton* browsePlusPathButton =
new QToolButton(
this);
66 browsePlusPathButton->setDefaultAction(browsePlusPathAction);
68 layout->addWidget(plusPathLabel, line, 0);
69 layout->addWidget(mPlusPathComboBox, line, 1);
70 layout->addWidget(browsePlusPathButton, line, 2);
73 layout->addWidget(
new QLabel(
"Plus config File:",
this), line, 0);
76 mPlusConfigFileWidget->
setPaths(this->getPlusConfigFilePaths());
77 mPlusConfigFileWidget->
setFilename(
"Select Plus config file...");
79 layout->addWidget(mPlusConfigFileWidget, line, 1, 1, 2);
84 "Show PlusServer output",
85 "Display all output from PlusServer",
87 layout->addWidget(
new CheckBoxWidget(
this, mShowPlusOutput), line, 0, 1, 3);
91 warningText =
"<font color=red>Note! The start/stop tracking button is not correctly synchronized <br> when using the plus server.</font><br>";
92 QLabel* warningInfoLabel =
new QLabel(warningText);
93 layout->addWidget(warningInfoLabel, line, 0, 1, 3);
97 mConnectButton->setToolTip(
"Remove all saved clip planes from the selected volume");
98 connect(mConnectButton, &QPushButton::clicked,
this, &PlusConnectWidget::connectButtonClickedSlot);
99 layout->addWidget(mConnectButton, line, 0, 1, 3);
103 mFilePreviewWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
104 layout->addWidget(mFilePreviewWidget, line, 0, 1, 3);
113 void PlusConnectWidget::searchForPlus()
115 QString possiblePath = QDir::homePath() +
"/dev/plus-2.6/PlusB-bin/bin/PlusServer";
117 if(QFile::exists(possiblePath))
119 CX_LOG_DEBUG() <<
"Found PlusServer in: " << possiblePath;
120 mPlusPath = possiblePath;
124 QStringList PlusConnectWidget::getPlusConfigFilePaths()
128 retval << QString(CX_OPTIONAL_CONFIG_ROOT) +
"/plus";
132 void PlusConnectWidget::searchForPlusConfigFile()
138 if(QFile::exists(possiblePath))
140 CX_LOG_DEBUG() <<
"Found Plus config file in: " << possiblePath;
141 mPlusConfigFile = possiblePath;
145 void PlusConnectWidget::browsePlusPathSlot()
147 QFileInfo fileInfo(mPlusPath);
148 mPlusPath = QFileDialog::getOpenFileName(
this, tr(
"Find PlusServer executable"), fileInfo.absolutePath());
150 if(!mPlusPath.isEmpty())
152 mPlusPathComboBox->addItem( mPlusPath );
153 mPlusPathComboBox->setCurrentIndex( mPlusPathComboBox->currentIndex() + 1 );
157 void PlusConnectWidget::configFileFileSelected(QString filename)
159 mPlusConfigFile = filename;
161 QFileInfo fileinfo(filename);
162 mPlusConfigFileWidget->
setPath(fileinfo.absolutePath());
168 void PlusConnectWidget::connectButtonClickedSlot()
172 CX_LOG_INFO() <<
"Stopping PlusServer and disconnecting";
176 mPlusRunning =
false;
183 CX_LOG_INFO() <<
"Starting PlusServer and connecting";
184 if(this->startPlus())
193 bool PlusConnectWidget::stopPlus()
200 streamerService->stop();
202 if(mExternalProcess->isRunning())
203 mExternalProcess->getProcess()->close();
206 mServices->video()->closeConnection();
209 disconnect(mExternalProcess->getProcess(), &QProcess::readyRead,
this, &PlusConnectWidget::processReadyRead);
212 return mExternalProcess->waitForFinished(1000);
216 bool PlusConnectWidget::startPlus()
222 if(!this->startExternalPlusServer())
226 this->changeOpenIGTLinkStreamerParameter(streamerService, QString(
OPENIGTLINK3_STREAMER_IP), QVariant(
"127.0.0.1"));
227 this->startOpenIGTLink3VideoStreaming();
232 void PlusConnectWidget::startOpenIGTLink3VideoStreaming()
235 mServices->video()->openConnection();
238 void PlusConnectWidget::plusAppStateChanged()
240 if(mExternalProcess->getProcess()->state() == QProcess::Starting)
242 mConnectButton->setText(
"PlusServer starting...");
246 if(!mExternalProcess->isRunning())
248 CX_LOG_DEBUG() <<
"plusAppStateChanged not running. Stopping...";
249 mPlusRunning =
false;
261 bool PlusConnectWidget::startExternalPlusServer()
263 if(!this->configFileIsValid())
266 QStringList arguments;
268 arguments << QString(
"--config-file=").append(mPlusConfigFile);
271 if(mShowPlusOutput->getValue())
273 QProcess *process = mExternalProcess->getProcess();
274 connect(process, &QProcess::readyRead,
this, &PlusConnectWidget::processReadyRead);
275 process->setProcessChannelMode(QProcess::MergedChannels);
276 process->setReadChannel(QProcess::StandardOutput);
281 arguments << QString(
"--verbose=1");
284 mExternalProcess->launch(mPlusPath, arguments);
285 return mExternalProcess->waitForStarted(1000);
288 bool PlusConnectWidget::configFileIsValid()
290 QFileInfo fileInfo(mPlusConfigFile);
291 if(fileInfo.exists())
295 CX_LOG_WARNING() <<
"Plus config file is not existing: " << mPlusConfigFile;
300 void PlusConnectWidget::processReadyRead()
302 report(QString(mExternalProcess->getProcess()->readAllStandardOutput()));
305 QDomElement PlusConnectWidget::getXmlVideoElement()
308 QDomElement element = xmlFile.
getElement(
"video");
312 void PlusConnectWidget::changeOpenIGTLinkStreamerParameter(
StreamerServicePtr streamerService, QString parameterName, QVariant value)
314 QDomElement element = this->getXmlVideoElement();
316 std::vector<PropertyPtr>
settings = streamerService->getSettings(element);
317 for(
unsigned i = 0; i < settings.size(); ++i)
319 if (settings[i]->getUid().contains(parameterName))
321 CX_LOG_DEBUG() <<
"Changing parameter " << parameterName <<
" to: " << value.toString() <<
" in OpenIGTLinkStreamer";
322 settings[i]->setValueFromVariant(value);
331 CX_LOG_WARNING() <<
"PlusConnectWidget::getOpenIGTLinkStreamerService(): Cannot get StreamerServicePtr";
cxResource_EXPORT ProfilePtr profile()
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
boost::shared_ptr< class VisServices > VisServicesPtr
#define OPENIGTLINK3_STREAMER
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
QDomElement getElement()
return the current element
Settings * settings()
Shortcut for accessing the settings instance.
static QString getRootConfigPath()
return path to root config folder. May be replaced with getExistingConfigPath()
#define OPENIGTLINK3_STREAMER_IP
#define OPENIGTLINK3_STREAMER_START_TRACKING
boost::shared_ptr< class StreamerService > StreamerServicePtr
Helper class for xml files used to store ssc/cx data.
Namespace for all CustusX production code.