Skip to content

Commit f71023f

Browse files
Qt: OpenIGTLink: add server socket handling
1 parent 5568f0f commit f71023f

File tree

6 files changed

+93
-3
lines changed

6 files changed

+93
-3
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "openigtlink.h"
2+
3+
bool SolumIGTL::serve(uint16_t port)
4+
{
5+
server_ = igtl::ServerSocket::New();
6+
if (server_->CreateServer(port) < 0)
7+
return false;
8+
return true;
9+
}
10+
11+
void SolumIGTL::close()
12+
{
13+
server_->CloseSocket();
14+
}
15+
16+
bool SolumIGTL::isServing() const
17+
{
18+
return (server_ && server_->GetConnected());
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include "igtlServerSocket.h"
4+
5+
/// OpenIGTLink module
6+
class SolumIGTL : public QObject
7+
{
8+
Q_OBJECT;
9+
10+
public:
11+
bool serve(uint16_t port); /// Returns `false` on failure.
12+
void close();
13+
14+
bool isServing() const;
15+
16+
private:
17+
igtl::ServerSocket::Pointer server_;
18+
};

examples/solum_qt/solum/solum.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ PRECOMPILED_HEADER = pch.h
77

88
CONFIG(release, debug|release): CONFIG += ltcg
99

10+
include($$PWD/../../../openigtlink/openigtlink.pri)
11+
1012
# ensure to unpack the appropriate libs from the zip file into this folder
1113
LIBPATH = $$PWD/../../../lib
1214
INCLUDEPATH += $$PWD/../../../include/solum
1315
LIBS += -L$$LIBPATH/ -lsolum
1416

15-
SOURCES += main.cpp solumqt.cpp ble.cpp display.cpp 3d.cpp jobbutton.cpp
16-
HEADERS += solumqt.h ble.h display.h 3d.h jobbutton.h
17+
SOURCES += main.cpp solumqt.cpp ble.cpp display.cpp 3d.cpp jobbutton.cpp openigtlink.cpp
18+
HEADERS += solumqt.h ble.h display.h 3d.h jobbutton.h openigtlink.h
1719
FORMS += solumqt.ui
1820

1921
RESOURCES += \

examples/solum_qt/solum/solumqt.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Solum::Solum(QWidget *parent) : QMainWindow(parent), imaging_(false)
2323
.arg(portValidator_->bottom())
2424
.arg(portValidator_->top());
2525

26+
connectPortChanged(ui_.igtlport, ui_.igtlserve);
27+
2628
// UI polish handlers
2729
connect(ui_.token, &QLineEdit::textChanged, [this](auto& text)
2830
{
@@ -62,6 +64,9 @@ Solum::Solum(QWidget *parent) : QMainWindow(parent), imaging_(false)
6264
settings_->endGroup();
6365
}
6466
settings_->endGroup();
67+
auto igtlport = settings_->value("OpenIGTLink/port").toString();
68+
if (!igtlport.isEmpty())
69+
ui_.igtlport->setText(igtlport);
6570

6671
ui_.certtable->setColumnCount(4);
6772
ui_.certtable->setHorizontalHeaderLabels({tr("Serial number"),
@@ -1077,3 +1082,28 @@ void Solum::connectPortChanged(QLineEdit* portEdit, QPushButton* connectButton)
10771082
}
10781083
});
10791084
}
1085+
1086+
void Solum::onIGTLServe()
1087+
{
1088+
const auto port = ui_.igtlport->text().toInt();
1089+
if (!igtl_.isServing())
1090+
{
1091+
settings_->setValue("OpenIGTLink/port", port);
1092+
if (igtl_.serve(port))
1093+
{
1094+
ui_.igtlStatusServer->setText(tr("🟢 Server is running"));
1095+
ui_.igtlport->setEnabled(false);
1096+
ui_.igtlserve->setText(tr("Stop"));
1097+
}
1098+
else
1099+
ui_.igtlStatusServer->setText(
1100+
tr("❌ Socket could not be opened on port %1").arg(port));
1101+
}
1102+
else
1103+
{
1104+
igtl_.close();
1105+
ui_.igtlStatusServer->setText(tr("🔴 Server is stopped"));
1106+
ui_.igtlport->setEnabled(true);
1107+
ui_.igtlserve->setText(tr("Serve"));
1108+
}
1109+
}

examples/solum_qt/solum/solumqt.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include "ble.h"
4-
#include <solum_def.h>
4+
#include "openigtlink.h"
55
#include "ui_solumqt.h"
66
#include <solum_def.h>
77

@@ -272,6 +272,7 @@ public slots:
272272
void tgcTop(int);
273273
void tgcMid(int);
274274
void tgcBottom(int);
275+
void onIGTLServe();
275276

276277
private:
277278
QString bleConnectedProbe_; ///< serial of the probe connected via BLE
@@ -291,4 +292,7 @@ public slots:
291292
std::unique_ptr<QSettings> settings_; ///< persistent settings
292293
QIntValidator* portValidator_; ///< keeps port fields between 1 and 65535
293294
QString portError_; ///< error message for port validation
295+
296+
std::optional<uint16_t> igtlport_; ///< OpenIGTLink port
297+
SolumIGTL igtl_; ///< OpenIGTLink module
294298
};

examples/solum_qt/solum/solumqt.ui

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,22 @@ After clicking the button, wait for the SSID to be published via BLE, then conne
14981498
</hint>
14991499
</hints>
15001500
</connection>
1501+
<connection>
1502+
<sender>igtlserve</sender>
1503+
<signal>clicked()</signal>
1504+
<receiver>Solum</receiver>
1505+
<slot>onIGTLServe()</slot>
1506+
<hints>
1507+
<hint type="sourcelabel">
1508+
<x>20</x>
1509+
<y>20</y>
1510+
</hint>
1511+
<hint type="destinationlabel">
1512+
<x>20</x>
1513+
<y>20</y>
1514+
</hint>
1515+
</hints>
1516+
</connection>
15011517
</connections>
15021518
<slots>
15031519
<slot>onTcpConnect()</slot>
@@ -1528,5 +1544,6 @@ After clicking the button, wait for the SSID to be published via BLE, then conne
15281544
<slot>onOpacity(int)</slot>
15291545
<slot>onAutoFocus(int)</slot>
15301546
<slot>onFocus(int)</slot>
1547+
<slot>onIGTLServe()</slot>
15311548
</slots>
15321549
</ui>

0 commit comments

Comments
 (0)