YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
mainwindow.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#ifndef MAINWINDOW_H
7#define MAINWINDOW_H
8
9#include <QMainWindow>
10#include <QWaitCondition>
11#include <QMutex>
12#include <QTreeWidgetItem>
13#include <QCloseEvent>
14#include <QThread>
15#include <QTimer>
16#include <string>
17#include <iostream>
18#include <string>
19#include <map>
20#include <fstream>
21#include "include/utils.h"
22#include "include/worker.h"
24#include <yarp/os/Value.h>
25#include <yarp/os/Bottle.h>
26#include <yarp/os/RpcClient.h>
27#include <yarp/os/RpcServer.h>
28#include "yarpdataplayer_IDL.h"
30#include <yarp/dataplayer/YarpDataplayer.h>
31
32class InitThread;
33
34namespace Ui {
35class MainWindow;
36}
37
38class MainWindow : public QMainWindow, public yarp::os::ResourceFinder, public yarpdataplayer_IDL
39{
40 Q_OBJECT
41 friend class QUtilities;
42
43public:
44 explicit MainWindow(yarp::os::ResourceFinder &rf,QWidget *parent = 0);
46
50 void addPart(const char* szName, const char* type, int frames, const char* portName, const char* szFileName=NULL);
54 bool setPartProgress(const char* szName, int percentage);
58 bool setInitialPartProgress(const char* szName, int percentage);
59
63 bool getPartPort(const char* szName, QString *dest);
67 bool setFrameRate(const char* szName, int frameRate);
71 bool setTimeTaken(const char* szName, double time);
75 void setPlayProgress(int percentage);
76
80 bool attach(yarp::os::RpcServer &source);
84 bool step() override;
88 bool setFrame(const int frameNum) override;
92 int getFrame(const std::string &name) override;
96 bool load(const std::string &path) override;
100 int getSliderPercentage() override;
104 std::string getStatus() override;
108 bool play() override;
112 bool pause() override;
116 bool stop() override;
120 bool quit() override;
121
122
123private:
127 void setupActions();
131 void setupSignals();
135 bool doGuiSetup(QString newPath);
139 void goToPercentage(int value);
143 bool safeExit();
147 bool cmdSafeExit();
148
149 QTreeWidgetItem *getRowByPart(QString szName);
150
151protected:
155 bool updateFrameNumber(int number);
159 void createUtilities();
163 void clearUtilities();
167 void getFrameCmd(const char* part, int *frame);
172
173 void closeEvent(QCloseEvent *event) override;
174
175private:
176
177 Ui::MainWindow *ui;
178 QString moduleName;
179 bool add_prefix; //indicates if ports have to be opened with /<moduleName> as prefix
180 bool verbose;
181 std::string dataset;
182 yarp::os::RpcServer rpcPort;
183 std::vector<yarp::yarpDataplayer::RowInfo> rowInfoVec;
184 int subDirCnt;
185 std::vector<std::string> dataType;
186
187 QMutex waitMutex;
188 QWaitCondition waitCond;
189
190 int percentage;
191 QMutex mutex;
192 bool pressed;
193 InitThread *initThread;
194 LoadingWidget loadingWidget;
195 QString errorMessage;
196
197protected:
199
200 std::map<const char*,int> partMap;
201 int itr;
205
206
207public slots:
211 bool getPartActivation(const char* szName);
212
213signals:
215 void internalLoad(QString);
220 void internalSetFrame(const int frameNum);
221 void internalGetFrame(const std::string &name, int *frame);
222 void internalGetSliderPercentage(int * percentage);
223
224private slots:
225 void onInternalQuit();
226 void onItemDoubleClicked(QTreeWidgetItem *item,int column);
227 void onErrorMessage(QString msg);
228 void onInitDone(int subDirCount);
229 void onMenuFileOpen();
230 void onMenuPlayBackPlay();
231 void onMenuPlayBackPause();
232 void onMenuPlayBackStop();
233 void onMenuPlayBackForward();
234 void onMenuPlayBackBackward();
235 void onMenuPlayBackStrict();
236 void onMenuPlayBackRepeat();
237 void onMenuHelpAbout();
238 void onMenuSpeedUp();
239 void onMenuSpeedDown();
240 void onMenuSpeedNormal();
241 void onUpdateGuiRateThread();
242 void onSpeedValueChanged(int value);
243 void onSliderPressed();
244 void onSliderReleased();
245 void onClose();
246 void resetButtonOnStop();
247
248 void onInternalLoad(QString);
249 void onInternalPlay();
250 void onInternalPause();
251 void onInternalStop();
252 void onInternalStep(yarp::os::Bottle *reply);
253 void onInternalSetFrame(const int frameNum);
254 void onInternalGetFrame(const std::string &name, int *frame);
255 void onInternalGetSliderPercentage(int *frame);
256
257};
258
259/***********************************************************/
260class InitThread : public QThread
261{
262 Q_OBJECT
263
264public:
265 InitThread(QUtilities *qutilities,
266 QString newPath,
267 std::vector<yarp::yarpDataplayer::RowInfo>& rowInfoVec,
268 QObject *parent = 0);
269
270protected:
271 void run() override;
272
273private:
274 QUtilities *qutilities;
275 QString newPath;
276 QMainWindow *mainWindow;
277 std::vector<yarp::yarpDataplayer::RowInfo> rowInfoVec;
278signals:
279 void initDone(int subDirCount);
280};
281#endif // MAINWINDOW_H
void initDone(int subDirCount)
void run() override
MainWindow class.
Definition display.h:22
bool quit() override
function that handles an IDL message - quit
void closeEvent(QCloseEvent *event) override
void stepFromCommand(yarp::os::Bottle &reply)
function steps datasets when requeted from terminal
void internalSetFrame(const int frameNum)
bool setFrame(const int frameNum) override
function that handles an IDL message - setFrame
bool pause() override
function that handles an IDL message - pause
bool stop() override
function that handles an IDL message - stop
bool getPartActivation(const char *szName)
function that gets which parts are activated
bool load(const std::string &path) override
function that handles an IDL message - load
void addPart(const char *szName, const char *type, int frames, const char *portName, const char *szFileName=NULL)
function that adds a data part to the main window
bool setPartProgress(const char *szName, int percentage)
function that sets the dataset part progress bar
bool setInitialPartProgress(const char *szName, int percentage)
function that sets the initial dataset part progress bar
QUtilities * qutilities
Definition mainwindow.h:198
void internalGetFrame(const std::string &name, int *frame)
void internalGetSliderPercentage(int *percentage)
bool setTimeTaken(const char *szName, double time)
function that sets the time taken
void internalLoad(QString)
int getSliderPercentage() override
function that returns slider percentage
void internalPlay()
bool quitFromCmd
Definition mainwindow.h:204
bool setFrameRate(const char *szName, int frameRate)
function that sets the frame rate
void internalStep(yarp::os::Bottle *reply)
bool getPartPort(const char *szName, QString *dest)
function that handles individual dataset part ports
void setPlayProgress(int percentage)
function that sets the play progress bar
bool updateFrameNumber(int number)
function that updates the frame number
bool step() override
function that that handles an IDL message - step
void createUtilities()
function that creates utilities
void internalQuit()
int getFrame(const std::string &name) override
function that handles an IDL message - getFrame
void clearUtilities()
function that deletes utilities
void internalStop()
std::string getStatus() override
function that returns the player status (playing, paused, stopped)
bool play() override
function that handles an IDL message - play
void getFrameCmd(const char *part, int *frame)
function that gets the frame command
bool attach(yarp::os::RpcServer &source)
function that that attaches the rpcServer port for IDL
std::map< const char *, int > partMap
Definition mainwindow.h:200
void internalPause()
bool withExtraTimeCol
Definition mainwindow.h:203
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
Helper class for finding config files and other external resources.
A port that is specialized as an RPC server.
Definition RpcServer.h:23
yarpdataplayer_IDL Interface.
Definition aboutdlg.h:11