-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOpenIGTLinkSimulatorApp.cpp
236 lines (194 loc) · 6.43 KB
/
OpenIGTLinkSimulatorApp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*=========================================================================
Program: OpenIGTLink Simulator
Language: C++
Copyright (c) Brigham and Women's Hospital. All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <iostream>
#include <QtGui>
#include "OpenIGTLinkSimulatorApp.h"
#include "igtlOSUtil.h"
#include "igtlImageMessage.h"
#include "igtlServerSocket.h"
#include "igtlMultiThreader.h"
#include "igtlOSUtil.h"
#include "igtlTCPConnectorServerOIGTL.h"
#include "qDataGeneratorTracking.h"
const int OpenIGTLinkSimulatorApp::StatusColorTable[][3] = {
{100, 100, 100}, // STOP
{100, 100, 200}, // WAITING
{100, 200, 100}, // CONNECTED
{200, 100, 100} // ERROR
};
const int OpenIGTLinkSimulatorApp::DataIOColorTable[][3] = {
{50, 50, 50}, // None
{100, 200, 100}, // Received
{200, 100, 100} // ERROR
};
OpenIGTLinkSimulatorApp::OpenIGTLinkSimulatorApp(QWidget *NOTUSED(parent))
{
setupUi(this); // this sets up GUI
fScannerActive = false;
fClientActive = false;
// Signals and Slots
connect(pbQuit, SIGNAL( clicked() ), this, SLOT( quit() ));
connect(pbAbout, SIGNAL( clicked() ), this, SLOT( about() ));
//connect(pbScannerActivate, SIGNAL( clicked() ), this, SLOT( scannerActivateClicked() ));
connect(pbClientActivate, SIGNAL( clicked() ), this, SLOT( clientActivateClicked() ));
//connect(leScannerAddress, SIGNAL( textChanged( const QString & ) ),
// this, SLOT( scannerAddressChanged( const QString & ) ));
//connect(leControlPort, SIGNAL( textChanged( const QString & ) ),
// this, SLOT( controlPortChanged( const QString & ) ));
//connect(leImagePort, SIGNAL( textChanged( const QString & ) ),
// this, SLOT( imagePortChanged( const QString & ) ));
connect(leOpenIGTLinkPort, SIGNAL( textChanged( const QString & ) ),
this, SLOT( igtlPortChanged( const QString & ) ));
// Default values
QString qs;
//leScannerAddress->setText(DEFAULT_RMP_ADDR);
leOpenIGTLinkPort->setText(qs.setNum(DEFAULT_OIGTL_PORT));
// Time for GUI update (every 200 ms)
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus()));
timer->start(200);
// Data Generator
this->TrackingDataGenerator = new qDataGeneratorTracking();
//// OpenIGTLink Server Socket
oigtlConnector = igtl::TCPConnectorServerOIGTL::New();
oigtlConnector->SetPort(18944);
this->TrackingDataGenerator->SetConnector(oigtlConnector);
this->TrackingDataGenerator->Start();
this->Threader = igtl::MultiThreader::New();
this->Threader->SpawnThread((igtl::ThreadFunctionType) &igtl::TCPConnectorServerOIGTL::MonitorThreadFunction,
oigtlConnector);
}
void OpenIGTLinkSimulatorApp::getPath()
{
QString path;
//path = QFileDialog::getOpenFileName(
// this,
// "Choose a file to open",
// QString::null,
// QString::null);
//
//lineEdit->setText( path );
}
void OpenIGTLinkSimulatorApp::about()
{
QMessageBox::about(this,
"About OpenIGTLinkSimulator",
"OpenIGTLink Simulator\n\n"
"Written by Junichi Tokuda\n"
"Brigham and Women's Hospital.\n\n"
"Copyright (C) 2011-2014\n"
);
}
void OpenIGTLinkSimulatorApp::scannerActivateClicked()
{
if (fScannerActive)
{
//pbScannerActivate->setText("Activate");
//fScannerActive = false;
}
else
{
//pbScannerActivate->setText("Deactivate");
//fScannerActive = true;
}
}
void OpenIGTLinkSimulatorApp::clientActivateClicked()
{
if (fClientActive)
{
fClientActive = false;
if (oigtlConnector.IsNotNull())
{
oigtlConnector->Deactivate();
}
}
else
{
fClientActive = true;
if (oigtlConnector.IsNotNull())
{
std::cerr << "Activating OpenIGTLink connector with:" << std::endl;
std::cerr << " Port: " << igtlPort.toInt() << std::endl;
oigtlConnector->SetPort(igtlPort.toInt());
oigtlConnector->Activate();
}
}
}
void OpenIGTLinkSimulatorApp::scannerAddressChanged( const QString & text )
{
scannerAddress = text;
}
void OpenIGTLinkSimulatorApp::imagePortChanged( const QString & text )
{
imagePort = text;
}
void OpenIGTLinkSimulatorApp::controlPortChanged( const QString & text )
{
controlPort = text;
}
void OpenIGTLinkSimulatorApp::igtlPortChanged( const QString & text )
{
igtlPort = text;
}
void OpenIGTLinkSimulatorApp::changeStatusTextColor(QLineEdit* le, int status)
{
if (status < igtl::TCPConnectorBase::STATUS_NUM && status >= 0)
{
QPalette p = le->palette();
p.setColor( le->backgroundRole(),
QColor(StatusColorTable[status][0],
StatusColorTable[status][1],
StatusColorTable[status][2]) );
le->setPalette(p);
}
}
void OpenIGTLinkSimulatorApp::changeDataIOTextColor(QLineEdit* le, int status)
{
if (status < 3 && status >= 0)
{
QPalette p = le->palette();
p.setColor( le->backgroundRole(),
QColor(DataIOColorTable[status][0],
DataIOColorTable[status][1],
DataIOColorTable[status][2]) );
le->setPalette(p);
}
}
void OpenIGTLinkSimulatorApp::updateStatus()
{
bool editClientFlag = true;
if (oigtlConnector.IsNotNull())
{
leStatusClient->setText(oigtlConnector->GetStatusString());
changeStatusTextColor(leStatusClient, oigtlConnector->GetStatus());
leOpenIGTLinkPort->setEnabled(oigtlConnector->GetStatus() == igtl::TCPConnectorBase::STATUS_STOP);
editClientFlag &= oigtlConnector->GetStatus() == igtl::TCPConnectorBase::STATUS_STOP;
if (oigtlConnector->GetStatus() == igtl::TCPConnectorBase::STATUS_STOP)
{
pbClientActivate->setText("Activate");
}
else
{
pbClientActivate->setText("Deactivate");
}
}
//bool editScannerFlag = true;
//leScannerAddress->setEnabled(editScannerFlag);
//leControlPort->setEnabled(editScannerFlag);
//leImagePort->setEnabled(editClientFlag);
}
void OpenIGTLinkSimulatorApp::quit()
{
if (oigtlConnector.IsNotNull())
{
oigtlConnector->CloseThread();
}
timer->stop();
close();
}