Commit 9ada8f14 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

first working version.

parent 055f32ef
......@@ -32,8 +32,10 @@ SETUP_PROJECT()
FIND_PACKAGE(Qt4 REQUIRED QtCore QtGui QtOpenGl)
ADD_REQUIRED_DEPENDENCY("openscenegraph >= 3.2")
ADD_REQUIRED_DEPENDENCY("openscenegraph-osgQt")
ADD_REQUIRED_DEPENDENCY("openthreads >= 3.2")
ADD_REQUIRED_DEPENDENCY("hpp-corbaserver")
ADD_REQUIRED_DEPENDENCY("gepetto-viewer-corba")
# Activate hpp-util logging if requested
SET (HPP_DEBUG FALSE CACHE BOOL "trigger hpp-util debug output")
......@@ -42,34 +44,58 @@ IF (HPP_DEBUG)
ENDIF()
SET (${PROJECT_NAME}_HEADERS
mainwindow.h
osgwidget.h
hpp-qt/corbaserver.hh
include/hpp/gui/mainwindow.h
include/hpp/gui/osgwidget.h
include/hpp/gui/configurationlistwidget.h
include/hpp/gui/pathplayer.h
include/hpp/gui/solverwidget.h
include/hpp/gui/tree-item.h
include/hpp/gui/ledindicator.h
include/hpp/gui/omniorb/omniorbthread.h
include/hpp/gui/dialog/dialogloadrobot.h
include/hpp/gui/dialog/dialogloadenvironment.h
)
SET (${PROJECT_NAME}_SOURCES
main.cc
mainwindow.cc
osgwidget.cc
hpp-qt/corbaserver.cc
SET(${PROJECT_NAME}_FORMS
include/hpp/gui/ui/mainwindow.ui
include/hpp/gui/ui/dialogloadrobot.ui
include/hpp/gui/ui/dialogloadenvironment.ui
)
SET(${PROJECT_NAME}_FORMS mainwindow.ui)
SET(${PROJECT_NAME}_RESOURCES res/images.qrc)
QT4_WRAP_CPP(${PROJECT_NAME}_HEADERS_MOC ${${PROJECT_NAME}_HEADERS})
QT4_WRAP_UI(${PROJECT_NAME}_FORMS_HEADERS ${${PROJECT_NAME}_FORMS})
QT4_ADD_RESOURCES(${PROJECT_NAME}_RESOURCES_RCC ${${PROJECT_NAME}_RESOURCES})
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
SET (${PROJECT_NAME}_SOURCES
src/main.cc
src/mainwindow.cc
src/configurationlistwidget.cc
src/osgwidget.cc
src/tree-item.cc
src/pathplayer.cc
src/solverwidget.cc
src/omniorbthread.cc
src/ledindicator.cc
src/dialog/dialogloadrobot.cc
src/dialog/dialogloadenvironment.cc
)
ADD_EXECUTABLE(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES}
${${PROJECT_NAME}_HEADERS_MOC}
${${PROJECT_NAME}_FORMS_HEADERS}
${${PROJECT_NAME}_RESOURCES_RCC}
)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${QT_LIBRARIES})
PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} openscenegraph)
PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} openthreads)
PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} hpp-corbaserver)
PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} gepetto-viewer-corba)
PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} openscenegraph-osgQt)
SETUP_PROJECT_FINALIZE()
#ifndef CORBASERVER_HH
#define CORBASERVER_HH
#include <QThread>
#include <QMutex>
#include <hpp/corbaserver/server.hh>
#include <omniORB4/CORBA.h>
class OmniORBThread : public QThread
{
Q_OBJECT
public:
OmniORBThread(int argc, const char **argv, QObject *parent = 0);
~OmniORBThread ();
protected:
void run ();
void timerEvent(QTimerEvent *event);
hpp::core::ProblemSolverPtr_t problemSolver_;
hpp::corbaServer::Server server_;
int interval_;
int timerId_;
QMutex serverLock_;
};
#endif // CORBASERVER_HH
#ifndef CONFIGURATIONLISTWIDGET_H
#define CONFIGURATIONLISTWIDGET_H
#include <QWidget>
#include "hpp/gui/fwd.h"
#include "hpp/gui/mainwindow.h"
#include "hpp/corbaserver/common.hh"
Q_DECLARE_METATYPE (hpp::floatSeq*)
class ConfigurationListWidget : public QWidget
{
Q_OBJECT
public:
static const int ConfigRole;
ConfigurationListWidget(QWidget* parent = 0);
virtual ~ConfigurationListWidget();
inline QListWidget* list () {
return findChild <QListWidget*> ("listConfigurations");
}
public slots:
void onSaveClicked ();
void updateCurrentConfig (QListWidgetItem* item);
void showListContextMenu (const QPoint& pos);
private:
inline QLineEdit* name () {
return findChild <QLineEdit*> ("lineEdit_configName");
}
MainWindow* main_;
QString basename_;
int count_;
};
#endif // CONFIGURATIONLISTWIDGET_H
#ifndef DIALOGLOADENVIRONMENT_H
#define DIALOGLOADENVIRONMENT_H
#include <QDialog>
#include <QComboBox>
namespace Ui {
class DialogLoadEnvironment;
}
class DialogLoadEnvironment : public QDialog
{
Q_OBJECT
public:
explicit DialogLoadEnvironment(QWidget *parent = 0);
~DialogLoadEnvironment();
struct EnvironmentDefinition {
QString name_, envName_, urdfFilename_, mesh_, package_, packagePath_;
EnvironmentDefinition () {}
EnvironmentDefinition (QString name, QString envName,
QString package, QString packagePath,
QString urdfFilename, QString meshDirectory) :
name_(name), envName_ (envName), urdfFilename_(urdfFilename),
mesh_(meshDirectory), package_ (package), packagePath_ (packagePath)
{}
};
static void addEnvironmentDefinition (QString name,
QString envName,
QString package,
QString packagePath,
QString urdfFilename,
QString meshDirectory);
EnvironmentDefinition getSelectedDescription () {
return selected_;
}
private slots:
void accept();
void meshSelect();
void packagePathSelect();
void envSelect(int index);
private:
Ui::DialogLoadEnvironment *ui_;
QComboBox* defs_;
EnvironmentDefinition selected_;
static QList <EnvironmentDefinition> definitions;
};
Q_DECLARE_METATYPE (DialogLoadEnvironment::EnvironmentDefinition)
#endif // DIALOGLOADENVIRONMENT_H
#ifndef DIALOGLOADROBOT_H
#define DIALOGLOADROBOT_H
#include <QDialog>
#include <QComboBox>
namespace Ui {
class DialogLoadRobot;
}
class DialogLoadRobot : public QDialog
{
Q_OBJECT
public:
struct RobotDefinition {
QString name_, robotName_, urdfSuf_, srdfSuf_, mesh_, package_, packagePath_, modelName_, rootJointType_;
RobotDefinition () : rootJointType_ ("Freeflyer") {}
RobotDefinition (QString name,
QString robotName,
QString rootJointType,
QString modelName,
QString package,
QString packagePath,
QString urdfSuffix,
QString srdfSuffix,
QString meshDirectory) :
name_(name), robotName_ (robotName), urdfSuf_(urdfSuffix), srdfSuf_(srdfSuffix), mesh_(meshDirectory),
package_ (package), packagePath_(packagePath), modelName_ (modelName),
rootJointType_ (rootJointType){}
};
explicit DialogLoadRobot(QWidget *parent = 0);
~DialogLoadRobot();
static void addRobotDefinition (QString name,
QString robotName,
QString rootJointType,
QString modelName,
QString package,
QString packagePath,
QString urdfSuffix,
QString srdfSuffix,
QString meshDirectory);
RobotDefinition getSelectedRobotDescription () {
return selected_;
}
private slots:
void accept();
void meshSelect();
void packagePathSelect();
void robotSelect(int index);
private:
Ui::DialogLoadRobot *ui_;
QComboBox* defs_;
RobotDefinition selected_;
static QList <RobotDefinition> definitions;
static QStringList rootJointTypes;
};
Q_DECLARE_METATYPE (DialogLoadRobot::RobotDefinition)
#endif // DIALOGLOADROBOT_H
#ifndef FWD_H
#define FWD_H
class MainWindow;
class JointTreeItem;
class SolverWidget;
class PathPlayer;
class ConfigurationListWidget;
class HppCorbaServer;
class ViewerCorbaServer;
#endif // FWD_H
#ifndef LEDINDICATOR_H
#define LEDINDICATOR_H
#include <QWidget>
class LedIndicator : public QWidget
{
Q_OBJECT
public:
LedIndicator (QWidget *parent = 0);
signals:
void switched (bool on);
public slots:
void switchLed();
void switchLed(bool on);
protected:
void paintEvent(QPaintEvent *);
private:
bool lit;
const int width, height;
};
#endif // LEDINDICATOR_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QMdiArea>
#include <QList>
#include "hpp/gui/osgwidget.h"
#include "hpp/gui/ledindicator.h"
#include "hpp/gui/omniorb/omniorbthread.h"
#include "hpp/gui/dialog/dialogloadrobot.h"
#include "hpp/gui/dialog/dialogloadenvironment.h"
#include "hpp/gui/fwd.h"
#include "hpp/core/fwd.hh"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
static MainWindow* instance ();
CorbaServer &hppServer();
hpp::corbaServer::Client* hppClient ();
BackgroundQueue &worker();
SolverWidget* solver() const;
graphics::WindowsManagerPtr_t osg () const;
OSGWidget* centralWidget() const;
void log (const QString& text);
void emitSendToBackground (WorkItem* item);
signals:
void sendToBackground (WorkItem* item);
public slots:
void logJobStarted (int id, const QString& text);
void logJobDone (int id, const QString& text);
void logJobFailed (int id, const QString& text);
void addBodyToTree (graphics::GroupNodePtr_t group);
void addJointToTree (const std::string name, JointTreeItem *parent);
void updateRobotJoints (const QString robotName);
void applyCurrentConfiguration ();
void requestConfigurationValidation ();
bool close();
private slots:
void onCreateView();
void openLoadRobotDialog ();
void openLoadEnvironmentDialog ();
void updateBodyTree (const QModelIndex& index);
void updateJointTree (const QModelIndex& index);
void showTreeContextMenu (const QPoint& point);
void handleWorkerDone (int id);
private:
void computeObjectPosition ();
Ui::MainWindow* ui_;
OSGWidget* centralWidget_;
QList <OSGWidget*> osgWindows_;
hpp::core::ProblemSolverPtr_t problemSolver_;
graphics::WindowsManagerPtr_t osgViewerManagers_;
CorbaServer hppServer_, osgServer_;
hpp::corbaServer::Client* hppClient_;
// graphics::corbaServer::Client* hppClient_;
BackgroundQueue backgroundQueue_;
QThread worker_;
SolverWidget* solver_;
LedIndicator* collisionIndicator_;
QStandardItemModel *bodyTreeModel_, *jointTreeModel_;
typedef QPair <std::string, std::string> JointLinkPair;
QList <JointLinkPair> jointsToLink_;
QMap <std::string, std::string> jointsToLinkMap_;
static MainWindow* instance_;
struct LoadDoneStruct {
LoadDoneStruct () : id (-1), parent (MainWindow::instance()) {}
virtual void done ();
bool isValid () { return id >= 0; }
void invalidate () { id = -1; }
bool is (int ID) { return id == ID; }
int id;
QString what;
MainWindow* parent;
};
friend struct LoadDoneStruct;
struct LoadRobot : public LoadDoneStruct {
std::string name_, urdfSuf_, srdfSuf_,
package_, modelName_, rootJointType_;
DialogLoadRobot::RobotDefinition rd;
virtual void done ();
};
struct LoadEnvironment : public LoadDoneStruct {
std::string prefix_, urdfFilename_, package_;
virtual void done ();
};
QList <LoadDoneStruct*> loader_;
};
#endif // MAINWINDOW_H
#ifndef OMNIORBTHREAD_H
#define OMNIORBTHREAD_H
#include <assert.h>
#include <QThread>
#include <QMutex>
#include <QTimerEvent>
#include <QElapsedTimer>
#include "hpp/gui/fwd.h"
#include "hpp/corbaserver/fwd.hh"
#include "gepetto/viewer/corba/fwd.hh"
class WorkItem {
public:
WorkItem () : id_ (idGlobal++) {}
virtual void performWork () = 0;
int id () const { return id_; }
protected:
void id (int i) { id_ = i; }
private:
static int idGlobal;
int id_;
};
template <typename Caller, typename ReturnType>
class WorkItem_0 : public WorkItem {
public:
typedef ReturnType (Caller::* Method) ();
WorkItem_0 (Caller* c, Method m) : caller (c), method (m) {}
void performWork () { (caller->*method) (); }
private:
Caller* caller;
Method method;
};
template <typename Caller, typename ReturnType, typename Arg0>
class WorkItem_1 : public WorkItem {
public:
typedef ReturnType (Caller::* Method) (Arg0);
WorkItem_1 (Caller* c, Method m, Arg0 a0) : caller (c), method (m),
arg0 (a0) {}
void performWork () { (caller->*method) (arg0); }
private:
Caller* caller;
Arg0 arg0;
Method method;
};
template <typename Caller, typename ReturnType, typename Arg0, typename Arg1>
class WorkItem_2 : public WorkItem {
public:
typedef ReturnType (Caller::* Method) (Arg0,Arg1);
WorkItem_2 (Caller* c, Method m, Arg0 a0, Arg1 a1) : caller (c), method (m),
arg0 (a0), arg1 (a1) {}
void performWork () { (caller->*method) (arg0, arg1); }
private:
Caller* caller;
Arg0 arg0;
Arg1 arg1;
Method method;
};
template <typename Caller, typename ReturnType,
typename Arg0, typename Arg1, typename Arg2>
class WorkItem_3 : public WorkItem {
public:
typedef ReturnType (Caller::* Method) (Arg0,Arg1,Arg2);
WorkItem_3 (Caller* c, Method m, Arg0 a0, Arg1 a1, Arg2 a2) : caller (c), method (m),
arg0 (a0), arg1 (a1), arg2 (a2) {}
void performWork () { (caller->*method) (arg0, arg1, arg2); }
private:
Caller* caller;
Arg0 arg0;
Arg1 arg1;
Arg2 arg2;
Method method;
};
template <typename Caller, typename ReturnType,
typename Arg0, typename Arg1, typename Arg2, typename Arg3>
class WorkItem_4 : public WorkItem {
public:
typedef ReturnType (Caller::* Method) (Arg0,Arg1,Arg2,Arg3);
WorkItem_4 (Caller* c, Method m, Arg0 a0, Arg1 a1, Arg2 a2, Arg3 a3) : caller (c), method (m),
arg0 (a0), arg1 (a1), arg2 (a2), arg3 (a3) {}
void performWork () { (caller->*method) (arg0, arg1, arg2, arg3); }
private:
Caller* caller;
Arg0 arg0;
Arg1 arg1;
Arg2 arg2;
Arg3 arg3;
Method method;
};
template <typename Caller, typename ReturnType,
typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
class WorkItem_5 : public WorkItem {
public:
typedef ReturnType (Caller::* Method) (Arg0,Arg1,Arg2,Arg3,Arg4);
WorkItem_5 (Caller* c, Method m, Arg0 a0, Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) : caller (c), method (m),
arg0 (a0), arg1 (a1), arg2 (a2), arg3 (a3), arg4 (a4) {}
void performWork () { (caller->*method) (arg0, arg1, arg2, arg3, arg4); }
private:
Caller* caller;
Arg0 arg0;
Arg1 arg1;
Arg2 arg2;
Arg3 arg3;
Arg4 arg4;
Method method;
};
template <typename Caller, typename ReturnType,
typename Arg0, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
class WorkItem_6 : public WorkItem {
public:
typedef ReturnType (Caller::* Method) (Arg0,Arg1,Arg2,Arg3,Arg4,Arg5);
WorkItem_6 (Caller* c, Method m, Arg0 a0, Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) : caller (c), method (m),
arg0 (a0), arg1 (a1), arg2 (a2), arg3 (a3), arg4 (a4), arg5 (a5) {}
void performWork () { (caller->*method) (arg0, arg1, arg2, arg3, arg4, arg5); }
private:
Caller* caller;
Arg0 arg0;
Arg1 arg1;
Arg2 arg2;
Arg3 arg3;
Arg4 arg4;
Arg5 arg5;
Method method;
};
class ServerProcess : public QObject
{
Q_OBJECT
signals:
void done ();
public slots:
virtual void init () = 0;
virtual void processRequest (bool loop) = 0;
};
class HppServerProcess : public ServerProcess
{
Q_OBJECT
public:
HppServerProcess (hpp::corbaServer::Server* server_);
~HppServerProcess () { delete server_; }
public slots:
void init ();
void processRequest (bool loop);
private:
hpp::corbaServer::Server* server_;
};
class ViewerServerProcess : public ServerProcess
{