Skip to content
Snippets Groups Projects
Commit 466f46c5 authored by hdallard's avatar hdallard
Browse files

Move hpp-gui core code to gepetto-viewer-corba

parent df34ad1f
No related branches found
No related tags found
No related merge requests found
Showing
with 1402 additions and 0 deletions
......@@ -52,7 +52,52 @@ PKG_CONFIG_APPEND_LIBS(${PROJECT_NAME})
INCLUDE_DIRECTORIES(SYSTEM ${EIGEN3_INCLUDE_DIRS})
SET (${PROJECT_NAME}_HEADERS_MOC
${CMAKE_SOURCE_DIR}/include/gepetto/gui/mainwindow.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/safeapplication.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/osgwidget.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/tree-item.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/bodytreewidget.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/ledindicator.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/plugin-interface.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/omniorb/omniorbthread.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/omniorb/url.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/dialog/dialogloadrobot.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/dialog/dialogloadenvironment.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/dialog/pluginmanagerdialog.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/pick-handler.hh
)
SET (${PROJECT_NAME}_HEADERS_NO_MOC
${CMAKE_SOURCE_DIR}/include/gepetto/gui/fwd.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/meta.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/settings.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/windows-manager.hh
${CMAKE_SOURCE_DIR}/include/gepetto/gui/color-map.hh
${CMAKE_BINARY_DIR}/include/gepetto/gui/config-dep.hh
)
SET(${PROJECT_NAME}_FORMS
${CMAKE_SOURCE_DIR}/include/gepetto/gui/ui/mainwindow.ui
${CMAKE_SOURCE_DIR}/include/gepetto/gui/ui/dialogloadrobot.ui
${CMAKE_SOURCE_DIR}/include/gepetto/gui/ui/dialogloadenvironment.ui
${CMAKE_SOURCE_DIR}/include/gepetto/gui/ui/pluginmanagerdialog.ui
)
SET(${PROJECT_NAME}_RESOURCES ${CMAKE_SOURCE_DIR}/res/images.qrc)
SET(${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_HEADERS}
${${PROJECT_NAME}_HEADERS_MOC}
${${PROJECT_NAME}_HEADERS_NO_MOC})
config_files(
include/gepetto/gui/config-dep.hh
src/gui/main.cc
src/gui/gepetto-gui
)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(src/gui)
ADD_SUBDIRECTORY(blender)
ADD_SUBDIRECTORY(examples EXCLUDE_FROM_ALL)
......
# Find PythonQt
#
# Sets PYTHONQT_FOUND, PYTHONQT_INCLUDE_DIR, PYTHONQT_LIBRARY, PYTHONQT_QTALL_LIBRARY, PYTHONQT_LIBRARIES
#
IF(NOT EXISTS "${PYTHONQT_INSTALL_DIR}")
FIND_PATH(PYTHONQT_INSTALL_DIR include/PythonQt/PythonQt.h
DOC "Directory where PythonQt was installed.")
ENDIF()
# XXX Since PythonQt 3.0 is not yet cmakeified, depending
# on how PythonQt is built, headers will not always be
# installed in "include/PythonQt". That is why "src"
# is added as an option. See [1] for more details.
# [1] https://github.com/commontk/CTK/pull/538#issuecomment-86106367
FIND_PATH(PYTHONQT_INCLUDE_DIR PythonQt.h
PATHS "${PYTHONQT_INSTALL_DIR}/include/PythonQt"
DOC "Path to the PythonQt include directory")
SET(PYTHONQT_LIBRARIES)
MACRO(_SEARCH_FOR COMPONENT)
STRING(TOUPPER ${COMPONENT} _COMP_UPPERCASE)
FIND_LIBRARY(${_COMP_UPPERCASE}_LIBRARY
NAMES ${COMPONENT}
PATHS "${PYTHONQT_INSTALL_DIR}/lib"
DOC "The ${COMPONENT} library.")
IF(NOT ${${_COMP_UPPERCASE}_LIBRARY} STREQUAL "${_COMP_UPPERCASE}_LIBRARY-NOTFOUND")
SET(${COMPONENT}_FOUND TRUE)
ENDIF(NOT ${${_COMP_UPPERCASE}_LIBRARY} STREQUAL "${_COMP_UPPERCASE}_LIBRARY-NOTFOUND")
MARK_AS_ADVANCED(${${_COMP_UPPERCASE}_LIBRARY})
SET(PYTHONQT_LIBRARIES ${PYTHONQT_LIBRARIES} ${${_COMP_UPPERCASE}_LIBRARY})
ENDMACRO(_SEARCH_FOR COMP)
_SEARCH_FOR(PythonQt)
FOREACH(_COMPONENT_SHORT ${PythonQt_FIND_COMPONENTS})
SET(_COMPONENT "PythonQt_${_COMPONENT_SHORT}")
_SEARCH_FOR(${_COMPONENT})
ENDFOREACH(_COMPONENT_SHORT ${PythonQt_FIND_COMPONENTS})
MARK_AS_ADVANCED(PYTHONQT_INSTALL_DIR)
MARK_AS_ADVANCED(PYTHONQT_INCLUDE_DIR)
MARK_AS_ADVANCED(PYTHONQT_LIBRARIES)
# All upper case _FOUND variable is maintained for backwards compatibility.
SET(PythonQt_FOUND 0)
IF(PYTHONQT_INCLUDE_DIR AND PYTHONQT_LIBRARIES)
# Currently CMake'ified PythonQt only supports building against a python Release build.
ADD_DEFINITIONS(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK)
SET(PythonQt_FOUND 1)
ENDIF()
SET(PYTHONQT_FOUND ${PythonQt_FOUND})
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonQt
REQUIRED_VARS PYTHONQT_LIBRARY PYTHONQT_INCLUDE_DIR
HANDLE_COMPONENTS)
#ifndef GEPETTO_GUI_BODYTREEWIDGET_HH
#define GEPETTO_GUI_BODYTREEWIDGET_HH
// This does not work because of qt meta-object compiler
#define GEPETTO_GUI_BODYTREE_DECL_FEATURE(func, ArgType) \
public slots: \
void func (ArgType arg)
#define GEPETTO_GUI_BODYTREE_IMPL_FEATURE(func, ArgType, CorbaType, WindowsManagerFunc) \
void BodyTreeWidget::func (ArgType arg) { \
WindowsManagerPtr_t wsm = MainWindow::instance()->osg(); \
foreach (const QModelIndex& index, view_->selectionModel ()->selectedIndexes ()) { \
const BodyTreeItem *item = dynamic_cast <const BodyTreeItem*> \
(model_->itemFromIndex (index)); \
if (item) wsm->WindowsManagerFunc (item->node()->getID().c_str(), \
Traits<CorbaType>::from (arg).in()); \
} \
}
#include <QWidget>
#include <QTreeView>
#include <QToolBox>
#include <QStandardItemModel>
#include <QVector3D>
#include <gepetto/viewer/group-node.h>
#include <gepetto/gui/fwd.hh>
namespace gepetto {
namespace gui {
class BodyTreeWidget : public QWidget
{
Q_OBJECT
public:
explicit BodyTreeWidget (QWidget* parent = NULL)
: QWidget (parent)
{}
void init(QTreeView *view, QToolBox* toolBox);
virtual ~BodyTreeWidget () {}
void addBodyToTree (graphics::GroupNodePtr_t group);
void changeAlphaValue(const float& alpha);
QTreeView* view ();
public slots:
void selectBodyByName (const QString bodyName);
void selectBodyByName (const std::string& bodyName);
void reloadBodyTree ();
protected slots:
void customContextMenu (const QPoint& pos);
public slots:
void setTransparency(int value);
void setVisibilityMode (QString arg);
void setWireFrameMode (QString arg);
void setColor (QColor color);
void setScale (int scale);
private:
QTreeView* view_;
QStandardItemModel* model_;
WindowsManagerPtr_t osg_;
QToolBox* toolBox_;
};
}
}
#endif // GEPETTO_GUI_BODYTREEWIDGET_HH
#ifndef GEPETTO_GUI_COLORMAP_HH
#define GEPETTO_GUI_COLORMAP_HH
#include <QColor>
#include <QDebug>
namespace gepetto {
namespace gui {
class ColorMap {
public:
static QColor interpolate (std::size_t nbColors, std::size_t index)
{
if (index > nbColors)
qDebug() << "Nb colors:" << nbColors << "and index" << index;
return QColor::fromHslF((qreal)index / (qreal)nbColors, 1, 0.5);
}
ColorMap (std::size_t nbColors) :
nbColors_ (nbColors),
currentIndex_ (0)
{
log2up_ = 0;
mask_ = 0;
std::size_t val = (nbColors > 0)?nbColors:1;
for (log2up_ = 0; val; ++log2up_, val >>= 1) mask_ = 2*mask_ + 1;
}
QColor getColor (std::size_t index) const {
return ColorMap::interpolate(mask_, remap (index));
}
void getColor (std::size_t index, float color[4]) const {
QColor c = getColor(index);
color[0] = (float)c.redF();
color[1] = (float)c.greenF();
color[2] = (float)c.blueF();
color[3] = (float)c.alphaF();
}
QColor nextColor () {
QColor color = getColor (currentIndex_);
currentIndex(currentIndex_ + 1);
return color;
}
void currentIndex (std::size_t index) {
currentIndex_ = index % nbColors_;
}
/// Reverse the order of the bits in index.
/// This increases the contrast between colors with close indexes.
std::size_t remap (const std::size_t& index) const {
std::size_t ret = 0;
std::size_t input = index;
for (std::size_t i = 0; i < log2up_; ++i) {
ret <<= 1;
if (input & 1) ++ret;
input >>= 1;
}
return ret;
}
private:
std::size_t nbColors_;
std::size_t mask_;
std::size_t log2up_;
std::size_t currentIndex_;
};
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_COLORMAP_HH
#ifndef GEPETTO_GUI_CONFIG_DEP_HH
# define PYTHON_CONFIG_DEP_HH
#cmakedefine01 GEPETTO_GUI_HAS_PYTHONQT
#endif // PYTHON_CONFIG_PYTHON_DEP_HH
#ifndef GEPETTO_GUI_DIALOGLOADENVIRONMENT_HH
#define GEPETTO_GUI_DIALOGLOADENVIRONMENT_HH
#include <QDialog>
#include <QComboBox>
namespace Ui {
class DialogLoadEnvironment;
}
namespace gepetto {
namespace gui {
class DialogLoadEnvironment : public QDialog
{
Q_OBJECT
public:
explicit DialogLoadEnvironment(QWidget *parent = 0);
~DialogLoadEnvironment();
struct EnvironmentDefinition {
QString name_, envName_, urdfFilename_, mesh_, package_, packagePath_, urdfSuf_,
srdfSuf_;
EnvironmentDefinition () {}
EnvironmentDefinition (QString name, QString envName,
QString package, QString packagePath,
QString urdfFilename, QString urdfSuffix, QString srdfSuffix,
QString meshDirectory) :
name_(name), envName_ (envName), urdfFilename_(urdfFilename),
mesh_(meshDirectory), package_ (package), packagePath_ (packagePath),
urdfSuf_(urdfSuffix), srdfSuf_(srdfSuffix)
{}
};
static void addEnvironmentDefinition (QString name,
QString envName,
QString package,
QString packagePath,
QString urdfFilename,
QString urdfSuffix,
QString srdfSuffix,
QString meshDirectory);
static QList <EnvironmentDefinition> getEnvironmentDefinitions ();
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;
};
} // namespace gui
} // namespace gepetto
Q_DECLARE_METATYPE (gepetto::gui::DialogLoadEnvironment::EnvironmentDefinition)
#endif // GEPETTO_GUI_DIALOGLOADENVIRONMENT_HH
#ifndef GEPETTO_GUI_DIALOGLOADROBOT_HH
#define GEPETTO_GUI_DIALOGLOADROBOT_HH
#include <QDialog>
#include <QComboBox>
namespace Ui {
class DialogLoadRobot;
}
namespace gepetto {
namespace gui {
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);
static QList <RobotDefinition> getRobotDefinitions ();
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;
};
} // namespace gui
} // namespace gepetto
Q_DECLARE_METATYPE (gepetto::gui::DialogLoadRobot::RobotDefinition)
#endif // GEPETTO_GUI_DIALOGLOADROBOT_HH
#ifndef GEPETTO_GUI_PLUGINMANAGERDIALOG_HH
#define GEPETTO_GUI_PLUGINMANAGERDIALOG_HH
#include <QDialog>
#include <QMap>
#include <QSignalMapper>
#include <QDir>
#include <QPluginLoader>
#include <QTableWidgetItem>
#include <gepetto/gui/plugin-interface.hh>
namespace Ui {
class PluginManagerDialog;
}
namespace gepetto {
namespace gui {
class PluginManager {
public:
typedef QPair <QString, QPluginLoader*> Pair;
typedef QMap <QString, QPluginLoader*> Map;
~PluginManager () {
qDeleteAll (plugins_);
}
const QMap <QString, QPluginLoader*>& plugins () const {
return plugins_;
}
bool add (const QString& name, QWidget* parent = NULL, bool load = false);
template <typename Interface> Interface* getFirstOf ();
template <typename Interface> QList <Interface*> get ();
static QIcon icon (const QPluginLoader* pl);
static QString status (const QPluginLoader* pl);
static void addPluginDir (const QString& path);
bool initPlugin (const QString& name);
bool unloadPlugin (const QString& name);
private:
template <typename Interface>
static const Interface* const_instance_cast (const QPluginLoader* pl);
QMap <QString, QPluginLoader*> plugins_;
static QList <QDir> pluginDirs_;
};
class PluginManagerDialog : public QDialog
{
Q_OBJECT
public:
explicit PluginManagerDialog(PluginManager* pm, QWidget *parent = 0);
~PluginManagerDialog();
public slots:
void onItemChanged (QTableWidgetItem* current, QTableWidgetItem* previous);
void contextMenu(const QPoint& pos);
void load (const QString& name);
void unload (const QString& name);
private:
static const std::size_t NAME;
static const std::size_t FILE;
static const std::size_t FULLPATH;
static const std::size_t VERSION;
void updateList ();
::Ui::PluginManagerDialog *ui_;
PluginManager* pm_;
QSignalMapper signalMapper_;
};
template <typename Interface>
Interface* PluginManager::getFirstOf ()
{
foreach (QPluginLoader* p, plugins_) {
if (p->isLoaded()) {
PluginInterface* check = qobject_cast <PluginInterface*> (p->instance());
if (check && check->isInit ()) {
Interface* pi = qobject_cast <Interface*> (p->instance());
if (pi) return pi;
}
}
}
return NULL;
}
template <typename Interface>
QList <Interface*> PluginManager::get ()
{
QList <Interface*> list;
foreach (QPluginLoader* p, plugins_) {
if (p->isLoaded()) {
PluginInterface* check = qobject_cast <PluginInterface*> (p->instance());
if (check && check->isInit ()) {
Interface* pi = qobject_cast <Interface*> (p->instance());
if (pi)
list.append(pi);
}
}
}
return list;
}
template <typename Interface>
const Interface* PluginManager::const_instance_cast (const QPluginLoader* pl)
{
return (const Interface*) qobject_cast <Interface*> (const_cast <QPluginLoader*>(pl)->instance());
}
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_PLUGINMANAGERDIALOG_HH
#ifndef GEPETTO_GUI_FWD_HH
#define GEPETTO_GUI_FWD_HH
#include <boost/shared_ptr.hpp>
#include <gepetto/gui/config-dep.hh>
namespace gepetto {
namespace gui {
class MainWindow;
class OSGWidget;
class PickHandler;
class BodyTreeWidget;
class ViewerCorbaServer;
class WindowsManager;
typedef boost::shared_ptr <WindowsManager> WindowsManagerPtr_t;
#if GEPETTO_GUI_HAS_PYTHONQT
class PythonWidget;
#endif
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_FWD_HH
#ifndef GEPETTO_GUI_LEDINDICATOR_HH
#define GEPETTO_GUI_LEDINDICATOR_HH
#include <QWidget>
namespace gepetto {
namespace gui {
class LedIndicator : public QWidget
{
Q_OBJECT
public:
LedIndicator (QWidget *parent = 0);
signals:
void switched (bool on);
void mouseClickEvent ();
public slots:
void switchLed();
void switchLed(bool on);
protected:
void paintEvent(QPaintEvent *);
void mouseReleaseEvent(QMouseEvent* event);
private:
bool lit;
const int width, height;
};
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_LEDINDICATOR_HH
#ifndef GEPETTO_GUI_MAINWINDOW_HH
#define GEPETTO_GUI_MAINWINDOW_HH
#include <QList>
#include <QStandardItemModel>
#include <QMainWindow>
#include <gepetto/viewer/group-node.h>
#include <gepetto/gui/fwd.hh>
#include <gepetto/gui/ledindicator.hh>
#include <gepetto/gui/omniorb/omniorbthread.hh>
#include <gepetto/gui/dialog/dialogloadrobot.hh>
#include <gepetto/gui/dialog/dialogloadenvironment.hh>
#include <gepetto/gui/dialog/pluginmanagerdialog.hh>
#include <gepetto/gui/settings.hh>
namespace Ui {
class MainWindow;
}
namespace gepetto {
namespace gui {
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
Settings* settings_;
explicit MainWindow(Settings* settings, QWidget *parent = 0);
~MainWindow();
static MainWindow* instance ();
void insertDockWidget (QDockWidget* dock,
Qt::DockWidgetArea area = Qt::AllDockWidgetAreas,
Qt::Orientation orientation = Qt::Horizontal);
void removeDockWidget (QDockWidget* dock);
BackgroundQueue &worker();
WindowsManagerPtr_t osg () const;
OSGWidget* centralWidget() const;
QList <OSGWidget*> osgWindows () const;
BodyTreeWidget* bodyTree () const;
PluginManager* pluginManager ();
void emitSendToBackground (WorkItem* item);
signals:
void sendToBackground (WorkItem* item);
void createView (QString name);
void refresh ();
void applyCurrentConfiguration();
void configurationValidation();
void selectJointFromBodyName(const QString bodyName);
public slots:
void log (const QString& text);
void logError (const QString& text);
void logJobStarted (int id, const QString& text);
void logJobDone (int id, const QString& text);
void logJobFailed (int id, const QString& text);
OSGWidget* delayedCreateView (QString name = "");
void requestRefresh ();
void requestApplyCurrentConfiguration ();
void requestConfigurationValidation ();
void configurationValidationStatusChanged (bool valid);
void configurationValidationStatusChanged (QStringList bodiesInCollision);
void requestSelectJointFromBodyName (const QString bodyName);
void onOpenPluginManager ();
private slots:
OSGWidget* onCreateView(QString name);
OSGWidget* onCreateView();
void openLoadRobotDialog ();
void openLoadEnvironmentDialog ();
void handleWorkerDone (int id);
void resetConnection ();
void about ();
private:
void setupInterface ();
void createCentralWidget ();
static MainWindow* instance_;
::Ui::MainWindow* ui_;
OSGWidget* centralWidget_;
QList <OSGWidget*> osgWindows_;
#if GEPETTO_GUI_HAS_PYTHONQT
PythonWidget* pythonWidget_;
#endif
WindowsManagerPtr_t osgViewerManagers_;
CorbaServer* osgServer_;
BackgroundQueue backgroundQueue_;
QThread worker_;
QCheckBox* collisionValidationActivated_;
LedIndicator* collisionIndicator_;
QStandardItemModel *bodyTreeModel_;
QMutex delayedCreateView_;
QStringList robotNames_;
QStringList lastBodiesInCollision_;
};
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_MAINWINDOW_HH
#ifndef GEPETTO_GUI_META_HH
#define GEPETTO_GUI_META_HH
#include <QString>
namespace gepetto {
namespace gui {
template <typename T> struct Traits;
template <> struct Traits <CORBA::String_var> {
typedef CORBA::String_var type;
static inline type from (const QString& s) { return (const char*)s.toLocal8Bit().data(); }
static inline type from (const std::string& s) { return s.c_str(); }
};
template <> struct Traits <QString> {
typedef CORBA::String_var CORBA_t;
static inline CORBA_t to_corba (const QString& s) { return (const char*)s.toLocal8Bit().data(); }
};
template <typename In, typename Out, std::size_t Size>
inline void convertSequence (const In* in, Out (&out)[Size]) {
for (size_t i = 0; i < Size; ++i) out[i] = (Out)in[i];
}
template <typename In, typename Out>
inline void convertSequence (const In* in, Out* out, const std::size_t& s) {
for (size_t i = 0; i < s; ++i) out[i] = (Out)in[i];
}
}
}
#endif // GEPETTO_GUI_META_HH
#ifndef GEPETTO_GUI_OMNIORBTHREAD_HH
#define GEPETTO_GUI_OMNIORBTHREAD_HH
#include <assert.h>
#include <QThread>
#include <QMutex>
#include <QTimerEvent>
#include <QElapsedTimer>
#include "gepetto/gui/fwd.hh"
#include "gepetto/viewer/corba/fwd.hh"
namespace gepetto {
namespace gui {
class WorkItem {
public:
WorkItem () : id_ (idGlobal++) {}
virtual ~WorkItem () {}
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;
Method method;
Arg0 arg0;
};
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;
Method method;
Arg0 arg0;
Arg1 arg1;
};
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;
Method method;
Arg0 arg0;
Arg1 arg1;
Arg2 arg2;
};
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;
Method method;
Arg0 arg0;
Arg1 arg1;
Arg2 arg2;
Arg3 arg3;
};
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;
Method method;
Arg0 arg0;
Arg1 arg1;
Arg2 arg2;
Arg3 arg3;
Arg4 arg4;
};
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;
Method method;
Arg0 arg0;
Arg1 arg1;
Arg2 arg2;
Arg3 arg3;
Arg4 arg4;
Arg5 arg5;
};
class ServerProcess : public QObject
{
Q_OBJECT
public:
ServerProcess () ;
void waitForInitDone ();
signals:
void done ();
public slots:
virtual void init ();
virtual void processRequest (bool loop) = 0;
protected:
QMutex initDone_;
};
class ViewerServerProcess : public ServerProcess
{
Q_OBJECT
public:
ViewerServerProcess (graphics::corbaServer::Server* server);
~ViewerServerProcess ();
public slots:
void init ();
void processRequest (bool loop);
private:
graphics::corbaServer::Server* server_;
};
class CorbaServer : public QObject
{
Q_OBJECT
public:
CorbaServer(ServerProcess* process);
~CorbaServer ();
void wait ();
void waitForInitDone ();
void start ();
signals:
void process (bool);
protected slots:
void timerEvent(QTimerEvent *event);
void processed ();
private:
ServerProcess* control_;
QThread worker_;
int timerId_, interval_;
};
class BackgroundQueue : public QObject
{
Q_OBJECT
public:
BackgroundQueue (QObject *parent = 0);
signals:
void done (int workId);
void failed (int workId, const QString& text);
public slots:
void perform(WorkItem* item);
};
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_OMNIORBTHREAD_HH
#ifndef GEPETTO_GUI_OMNIORB_URL_HH
#define GEPETTO_GUI_OMNIORB_URL_HH
#include <QString>
namespace gepetto {
namespace gui {
namespace omniOrb {
static inline QString IIOPurl (const QString& host, const QString& port)
{
QString hp;
if (host.isEmpty ()) {
if (!port.isEmpty ()) hp = QString ("localhost:%1").arg (port);
} else {
if (port.isEmpty ()) hp = QString ("%1:2809").arg (host);
else hp = QString ("%1:%2").arg(host).arg(port);
}
return QString ("corbaloc:iiop:%1/NameService").arg (hp);
}
} // namespace omniOrb
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_OMNIORB_URL_HH
#ifndef GEPETTO_GUI_OSGWIDGET_HH
#define GEPETTO_GUI_OSGWIDGET_HH
#include <QString>
#include <QThread>
#include <QLabel>
#include <QTimer>
#include <osg/ref_ptr>
#include <osgQt/GraphicsWindowQt>
#include <gepetto/viewer/window-manager.h>
#include <gepetto/gui/fwd.hh>
#include <gepetto/gui/windows-manager.hh>
namespace gepetto {
namespace gui {
class RenderThread : public QThread {
public:
RenderThread () :
QThread (), viewerPtr (0), refreshRate (30)
{}
virtual ~RenderThread();
osgViewer::ViewerRefPtr viewerPtr;
WindowsManagerPtr_t wsm_;
int refreshRate;
bool stop;
// QThread interface
protected:
void run();
};
class OSGWidget : public QWidget
{
Q_OBJECT
public:
typedef std::list <graphics::NodePtr_t> NodeList;
enum Mode {
CAMERA_MANIPULATION,
NODE_SELECTION,
NODE_MOTION
};
OSGWidget( WindowsManagerPtr_t wm,
std::string name,
MainWindow* parent = 0,
Qt::WindowFlags f = 0,
osgViewer::ViewerBase::ThreadingModel threadingModel=osgViewer::Viewer::SingleThreaded );
virtual ~OSGWidget();
WindowsManager::WindowID windowID () const;
signals:
void selected (QString name);
void requestMotion (graphics::NodePtr_t node, graphics::Node::Arrow direction,
float speed);
public slots:
void loadURDF (const QString robotName,
const QString urdf_file_path,
const QString meshDataRootDir);
virtual void onHome();
void changeMode (Mode mode);
void selectionMode ();
void cameraManipulationMode ();
void addFloor();
void attachToWindow (const std::string nodeName);
protected:
virtual void paintEvent( QPaintEvent* paintEvent );
private slots:
void transferSelected (QString name);
private:
osgGA::EventQueue* getEventQueue() const;
osg::ref_ptr<osgQt::GraphicsWindowQt> graphicsWindow_;
WindowsManagerPtr_t wsm_;
osg::ref_ptr<PickHandler> pickHandler_;
WindowsManager::WindowID wid_;
graphics::WindowManagerPtr_t wm_;
RenderThread render_;
osgViewer::ViewerRefPtr viewer_;
osg::ref_ptr <osgViewer::ScreenCaptureHandler> screenCapture_;
QPoint selectionStart_;
QPoint selectionEnd_;
graphics::NodePtr_t selectedNode_;
Mode mode_;
bool selectionFinished_;
std::list <graphics::NodePtr_t> processPoint ();
std::list <graphics::NodePtr_t> processSelection();
struct InfoBox {
QSize size_;
QPixmap selection_, record_;
QLabel* label_;
InfoBox (QWidget* parent);
void normalMode ();
void selectionMode ();
void recordMode ();
void setMode (Mode mode);
};
InfoBox infoBox_;
friend class PickHandler;
};
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_OSGWIDGET_HH
#ifndef GEPETTO_GUI_PICK_HANDLER_HH
#define GEPETTO_GUI_PICK_HANDLER_HH
#include <osgGA/GUIEventHandler>
#include <gepetto/viewer/node.h>
#include <QObject>
#include <QModelIndex>
#include <gepetto/gui/fwd.hh>
namespace gepetto {
namespace gui {
class PickHandler : public QObject, public osgGA::GUIEventHandler
{
Q_OBJECT
public:
PickHandler (WindowsManagerPtr_t wsm);
virtual ~PickHandler();
virtual bool handle( const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& aa );
void select (graphics::NodePtr_t node);
void getUsage (osg::ApplicationUsage &usage);
private slots:
void bodyTreeCurrentChanged (const QModelIndex &current,
const QModelIndex &previous);
signals:
void selected (QString name);
private:
std::list <graphics::NodePtr_t> computeIntersection (osgGA::GUIActionAdapter& aa,
const float& x, const float& y);
void setCameraToSelected (osgGA::GUIActionAdapter& aa, bool zoom);
WindowsManagerPtr_t wsm_;
OSGWidget* parent_;
graphics::NodePtr_t last_;
bool pushed_;
float lastX_, lastY_;
};
}
}
#endif // GEPETTO_GUI_PICK_HANDLER_HH
#ifndef GEPETTO_GUI_PLUGININTERFACE_HH
#define GEPETTO_GUI_PLUGININTERFACE_HH
#include <QtGui>
#include <QWidget>
#include <gepetto/gui/dialog/dialogloadrobot.hh>
#include <gepetto/gui/dialog/dialogloadenvironment.hh>
#include <omniORB4/CORBA.h>
namespace gepetto {
namespace gui {
const int DockKeyShortcutBase = Qt::CTRL + Qt::ALT;
class PluginInterface {
public:
PluginInterface ()
: errorMsg_ ("Not initalized")
, isInit_ (false)
{}
virtual ~PluginInterface () {}
virtual QString name () const = 0;
void doInit ()
{
try {
init ();
isInit_ = true;
} catch (const std::exception& e) {
errorMsg_ = QString (e.what ());
}
}
bool isInit () const
{
return isInit_;
}
const QString& errorMsg () const
{
return errorMsg_;
}
protected:
virtual void init () = 0;
private:
QString errorMsg_;
bool isInit_;
};
class JointAction : public QAction {
Q_OBJECT
public:
JointAction (const QString& actionName, const std::string& jointName, QObject* parent)
: QAction (actionName, parent)
, jointName_ (jointName)
{
connect (this, SIGNAL (triggered(bool)), SLOT(trigger()));
}
signals:
void triggered (const std::string jointName);
private slots:
void trigger () {
emit triggered(jointName_);
}
private:
const std::string jointName_;
};
class JointModifierInterface {
public:
virtual ~JointModifierInterface () {}
virtual JointAction* action (const std::string& jointName) const = 0;
};
class ModelInterface {
public:
virtual ~ModelInterface () {}
virtual void loadRobotModel (DialogLoadRobot::RobotDefinition rd) = 0;
virtual void loadEnvironmentModel (DialogLoadEnvironment::EnvironmentDefinition ed) = 0;
virtual std::string getBodyFromJoint (const std::string& jointName) const = 0;
};
class CorbaInterface {
public:
virtual ~CorbaInterface () {}
virtual void openConnection () = 0;
virtual void closeConnection () = 0;
/// return true if error was handled.
virtual bool corbaException (int jobId, const CORBA::Exception& excep) const = 0;
};
} // namespace gui
} // namespace gepetto
Q_DECLARE_INTERFACE (gepetto::gui::PluginInterface, "hpp-gui.plugins/0.0")
Q_DECLARE_INTERFACE (gepetto::gui::JointModifierInterface, "hpp-gui.plugin.joint-modifier/0.0")
Q_DECLARE_INTERFACE (gepetto::gui::ModelInterface, "hpp-gui.plugin.model/0.0")
Q_DECLARE_INTERFACE (gepetto::gui::CorbaInterface, "hpp-gui.plugin.corba/0.0")
#endif // GEPETTO_GUI_PLUGININTERFACE_HH
#ifndef GEPETTO_GUI_PYTHONWIDGET_HH
#define GEPETTO_GUI_PYTHONWIDGET_HH
#include <gepetto/gui/config-dep.hh>
#if ! GEPETTO_GUI_HAS_PYTHONQT
# error "hpp-gui was not compile with PythonQt dependency."
#endif
#include <QDockWidget>
#include <QLayout>
#include <QPushButton>
#include <PythonQt/PythonQt.h>
#include <PythonQt/PythonQt_QtAll.h>
#include <PythonQt/PythonQtScriptingConsole.h>
namespace gepetto {
namespace gui {
class PythonWidget : public QDockWidget
{
Q_OBJECT
public:
explicit PythonWidget(QWidget *parent = 0);
void addToContext(QString const& name, QObject *obj);
virtual ~PythonWidget();
private:
PythonQtObjectPtr mainContext_;
PythonQtScriptingConsole* console_;
QPushButton* button_;
signals:
public slots:
void browseFile();
};
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_PYTHONWIDGET_HH
#ifndef GEPETTO_GUI_SAFEAPPLICATION_HH
#define GEPETTO_GUI_SAFEAPPLICATION_HH
#include <QApplication>
namespace gepetto {
namespace gui {
class SafeApplication : public QApplication
{
Q_OBJECT
public:
explicit SafeApplication (int& argc, char ** argv);
virtual bool notify(QObject* receiver, QEvent* e);
signals:
void log (QString text);
};
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_SAFEAPPLICATION_HH
#ifndef GEPETTO_GUI_SETTINGS_HH
#define GEPETTO_GUI_SETTINGS_HH
#include <ostream>
#include <string>
#include <QString>
#include <QStringList>
#include <gepetto/gui/dialog/pluginmanagerdialog.hh>
namespace gepetto {
namespace gui {
class MainWindow;
struct Settings {
std::string configurationFile;
std::string predifinedRobotConf;
std::string predifinedEnvConf;
bool verbose;
bool noPlugin;
bool autoWriteSettings;
bool startGepettoCorbaServer;
int refreshRate;
std::string captureDirectory, captureFilename, captureExtension;
/// Set up default values
Settings ();
/// Update values accordingly with command arguments
int fromArgv (const int argc, char* const argv[]);
/// Update settings from setting files
void fromFiles ();
/// Write the settings to configuration files
void writeSettings ();
/// Get a setting
QVariant getSetting (const QString & key,
const QVariant & defaultValue = QVariant());
PluginManager pluginManager_;
QStringList pluginsToInit_;
void setMainWindow (MainWindow* main);
void initPlugins ();
std::ostream& print (std::ostream& os);
private:
void readRobotFile ();
void readEnvFile ();
void readSettingFile ();
void writeRobotFile ();
void writeEnvFile ();
void writeSettingFile ();
void addRobotFromString (const std::string& rbtStr);
void addEnvFromString (const std::string& envStr);
void addPlugin (const QString& plg, bool init);
inline void log (const QString& t);
inline void logError (const QString& t);
MainWindow* mw;
};
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_SETTINGS_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment