source: libs/QtGui/inc/samgargui.h @ 445

Revision 445, 4.9 KB checked in by lmalek, 10 years ago (diff)

Samgar edition by WRUT. Based on Qt. Initial import.

Line 
1#ifndef SAMGARGUI_H
2#define SAMGARGUI_H
3
4#include <QWidget>
5
6#include <QTime>
7#include <QFile>
8#include <QTimer>
9#include <QTableWidgetItem>
10
11#define TIMER_INTERVAL 100
12#define MIGRATE 1
13
14#include <iostream>
15#include <fstream>
16#include <string>
17
18#include <yarp/sig/all.h>
19#include <yarp/os/all.h>
20#include <SamgarVars.h>
21
22#include "SgConnection.h"
23#include "SgModuleContainer.h"
24#include "SgConnectionContainer.h"
25
26enum ServerType {LocalServer, GlobalServer};
27
28
29#if MIGRATE
30#include "SgMigration.h"
31#endif
32
33namespace Ui
34{
35    class SamgarGui;
36}
37
38class SamgarGui;
39
40class DataPort : public Sg::SgPortDataType
41{
42public:
43    SamgarGui* MyComponent;
44    DataPort(SamgarGui* MyComp);
45    ~DataPort();
46    virtual void onRead(yarp::os::Bottle& b);
47private:
48    bool hasitworked;
49};
50
51/*
52 *
53 */
54class QtModuleContainer : public QObject, public Sg::SgModuleContainer
55{
56    Q_OBJECT
57protected:
58    virtual void modified() const;
59public:
60signals:
61    void needToRefresh() const;
62protected:
63    void changeEvent(QEvent *e);
64};
65
66/*
67 *
68 */
69class QtConnectionContainer : public QObject, public Sg::SgConnectionContainer
70{
71    Q_OBJECT
72protected:
73    virtual void modified() const;
74public:
75signals:
76    void needToRefresh() const;
77protected:
78    void changeEvent(QEvent *e);
79};
80
81/*
82 *
83 */
84class SamgarGui : public QWidget
85{
86    Q_OBJECT
87public:
88    SamgarGui(QWidget *parent = 0);
89    ~SamgarGui();
90
91    void AddToLog(const std::string,int); // add string to 1 of 4 log levels
92
93
94public:
95    /*
96     *  Connection list
97     */
98    bool addConnection(const Sg::SgNameType& module1Name, const Sg::SgNameType& port1Name,
99                       const Sg::SgNameType& module2Name, const Sg::SgNameType& port2Name,
100                       Sg::SgConnection::SgProtocolType protocol,
101                       Sg::SgConnection::SgNetworkType network); // add new conection
102    bool delConnection(const Sg::SgNameType& module1Name, const Sg::SgNameType& port1Name,
103                       const Sg::SgNameType& module2Name, const Sg::SgNameType& port2Name,
104                       Sg::SgConnection::SgProtocolType protocol,
105                       Sg::SgConnection::SgNetworkType network); // del conection
106    /*
107     *  Modules list
108     */
109    bool addModule(const Sg::SgNameType & newModuleName);
110    bool addModulePort(const Sg::SgNameType & moduleName, const Sg::SgNameType & newPortName);
111    bool delModule(const Sg::SgNameType & moduleName);
112    bool delModulePort(const Sg::SgNameType & moduleName, const Sg::SgNameType & portName);
113
114private:
115    void connectionsUpdate(void); // update connection state
116    void modulesUpdate(void); // check if it is posible to connect to main ports
117    void GetModuleCommands(void); // geather information from the port for modules
118    void SendOffModuleList(void); // when modules are changed it propagate new module list
119
120#if MIGRATE
121    void UpdateMigrationProto(void); // update list of platform where can migrate
122    void RegisterMigrationPort (void); // add new migration port
123    bool Migrate (std::string nameofwhere); // megrate to server of given name
124    std::vector<std::string> MigrationPlatformsAvail; // list of possible migration platforms
125#endif
126
127    std::string NameOfServer;  // local yarp server name
128    std::string NameofMigrate; // migration port name on local yarp server
129
130    void ChangeServer(ServerType change); // change the current yarp server that aplication is communicationg with (change namespace)
131    void GetCurrentServerName(void); // set NameOfServer based uppon corrent yarp setings
132
133    QTime MyTime; // used for putting date in log file
134    // log files
135    QFile myFileforLog;
136    QFile myFileforModReport;
137    QFile myFileforMod;
138    QFile myFileforCon;
139
140    QTimer timer;
141
142    QtModuleContainer modules; // structure keeping all modules inormation, ports are included in modules
143    QtConnectionContainer  connections; // structure keeping all conections inormation
144
145    int WhatShownDebug[4]; // debug flags
146
147    Ui::SamgarGui *ui;
148    DataPort* mainPort;
149
150#if MIGRATE
151    Sg::MigrationPortClass *MigrationPort; //class used to perform migration process
152#endif
153
154private slots:
155    void timerCallback(void);
156    void changeDebugLevel(void);
157    void firstModuleComboBoxUpdate(void);
158    void firstModulePortComboBoxUpdate(void);
159    void secondModuleComboBoxUpdate(void);
160    void secondModulePortComboBoxUpdate(void);
161    void connectPorts(void);
162    void connectionSelect(int row, int column);
163    void UpdateConnectionTable(Sg::SgNameType connectionName);
164    void RefreshModulesTree(void);      // refresh information about modules - delete old and put new one
165    void RefreshConnectionsTable(void); // refresh information about connections - delete old and put new one
166    void startAllModules(void);
167    void stopAllModules(void);
168    void saveAll();
169    void loadAll();
170
171signals:
172    void connectionTableModified();
173    void connectionTableModified(Sg::SgNameType connectionName);
174
175protected:
176    void changeEvent(QEvent *e);
177};
178
179#endif // SAMGARGUI_H
Note: See TracBrowser for help on using the repository browser.