Commit c0760578 authored by roangel's avatar roangel
Browse files

Added src and include, made GUI compile with QtCreator stuff, to keep the...

Added src and include, made GUI compile with QtCreator stuff, to keep the development going. Need to add compilation with ROS stuff, catkin_make
parent 2f3e2ce1
...@@ -31,3 +31,6 @@ pps_ws/devel/ ...@@ -31,3 +31,6 @@ pps_ws/devel/
./pps_ws/src/d_fall_pps/crazyradio/cflib/bootloader/cloader.pyc ./pps_ws/src/d_fall_pps/crazyradio/cflib/bootloader/cloader.pyc
./pps_ws/src/d_fall_pps/crazyradio/leapsdk/__init__.pyc ./pps_ws/src/d_fall_pps/crazyradio/leapsdk/__init__.pyc
pps_ws/src/d_fall_gui/GUI_Qt/build*
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.0.2, 2017-04-18T16:57:38. --> <!-- Written by QtCreator 4.0.2, 2017-04-20T11:42:52. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
#-------------------------------------------------
#
# Project created by QtCreator 2017-04-20T11:20:48
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = CrazyFlyGUI
TEMPLATE = app
SOURCES += \
../../src/cornergrabber.cpp \
../../src/crazyFlyZone.cpp \
../../src/crazyFlyZoneTab.cpp \
../../src/main.cpp \
../../src/mainguiwindow.cpp \
../../src/myGraphicsRectItem.cpp \
../../src/myGraphicsScene.cpp \
../../src/myGraphicsView.cpp \
../../src/tablePiece.cpp
HEADERS += \
../../include/cornergrabber.h \
../../include/crazyFlyZone.h \
../../include/crazyFlyZoneTab.h \
../../include/mainguiwindow.h \
../../include/myGraphicsRectItem.h \
../../include/myGraphicsScene.h \
../../include/myGraphicsView.h \
../../include/tablePiece.h
FORMS += \
../../src/mainguiwindow.ui
This diff is collapsed.
#ifndef CORNERGRABBER_H
#define CORNERGRABBER_H
#include <QObject>
#include <QGraphicsItem>
#include <QGraphicsRectItem>
#include <QGraphicsTextItem>
#include <QGraphicsSceneHoverEvent>
#include <QGraphicsSceneMouseEvent>
#include <QColor>
#include <QPainter>
#include <QPen>
#include <QPointF>
#define GRABBER_HEIGHT 10
#define GRABBER_WIDTH 10
class CornerGrabber : public QGraphicsItem
{
public:
explicit CornerGrabber(QGraphicsItem *parent = 0, int corner = 0);
int getCorner(); ///< allows the owner to find out which coner this is
qreal getHeight();
qreal getWidth();
bool isActive();
QRectF rect() const;
enum {noCorner, bottomLeft, topLeft, topRight, bottomRight};
private:
virtual QRectF boundingRect() const; ///< must be re-implemented in this class to provide the diminsions of the box to the QGraphicsView
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); ///< must be re-implemented here to pain the box on the paint-event
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); ///< must be re-implemented to handle mouse hover enter events
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); ///< must be re-implemented to handle mouse hover leave events
// once the hover event handlers are implemented in this class,
// the mouse events must allow be implemented because of
// some linkage issue - apparrently there is some connection
// between the hover events and mouseMove/Press/Release
// events which triggers a vtable issue
virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
virtual void mouseMoveEvent(QGraphicsSceneDragDropEvent *event);
virtual void mousePressEvent (QGraphicsSceneMouseEvent * event );
virtual void mousePressEvent(QGraphicsSceneDragDropEvent *event);
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent * event );
QRectF createRect();
void setRect(const QRectF & rectangle);
QColor _outterborderColor; ///< the hover event handlers will toggle this between red and black
QPen _outterborderPen; ///< the pen is used to paint the red/black border
qreal _width;
qreal _height;
int _corner;// 0,1,2,3 - starting at x=0,y=0 and moving clockwise around the box
bool _is_active;
QRectF _rect;
};
#endif // CORNERGRABBER_H
#ifndef CRAZYFLYZONE_H
#define CRAZYFLYZONE_H
#include <QGraphicsSimpleTextItem>
#include "myGraphicsRectItem.h"
class crazyFlyZone : public myGraphicsRectItem
{
public:
explicit crazyFlyZone(const QRectF & rect, int index, QGraphicsItem * parent = 0);
int getIndex();
void setIndex(int index);
void setLabel(QString string);
void setLabelPosition();
void updateLabel(QString string);
void rectSizeChanged();
protected:
private:
int _index;
QGraphicsSimpleTextItem* label;
};
#endif
#ifndef CRAZYFLYZONETAB_H
#define CRAZYFLYZONETAB_H
#include <QObject>
#include <QWidget>
#include <QPushButton>
class crazyFlyZoneTab : public QWidget
{
Q_OBJECT
public:
explicit crazyFlyZoneTab(int index, QWidget *parent = 0);
QPushButton* center_button;
private:
int _index;
int _num_rows;
int _num_columns;
signals:
void centerButtonClickedSignal(int index);
public slots:
void centerButtonClicked();
};
#endif
#ifndef MAINGUIWINDOW_H
#define MAINGUIWINDOW_H
#define DEBUG_GUI
#include <QMainWindow>
#include <QTimer>
#include <QGridLayout>
#include <QGraphicsRectItem>
#ifndef DEBUG_GUI
#include "ros/callback_queue.h"
#include "ros/ros.h"
#include "CrazyFlieTypes.h"
#endif
#include "ui_mainguiwindow.h"
#include "myGraphicsScene.h"
namespace Ui {
class MainGUIWindow;
}
#ifndef DEBUG_GUI
struct setpoint
{
double x;
double y;
double z;
double yaw;
};
class CSetpointQueue
{
public:
CSetpointQueue();
void insert(setpoint newElem);
setpoint getNext();
void print();
private:
struct QueueElem
{
QueueElem(setpoint newElem) {elem.x=newElem.x; elem.y=newElem.y; elem.z=newElem.z; elem.yaw=newElem.yaw; next=NULL;}
setpoint elem;
QueueElem* next;
};
QueueElem* startElem;
QueueElem* currElem;
QueueElem* lastElem;
};
#endif
class MainGUIWindow : public QMainWindow
{
Q_OBJECT
public:
#ifdef DEBUG_GUI
explicit MainGUIWindow(/*ros::NodeHandle* ,*/ /*ros::CallbackQueue* callbackQueue, ros::Publisher* publisherMotorCommandsGUI,*/ QWidget *parent = 0);
#else
explicit MainGUIWindow(ros::NodeHandle* , /*ros::CallbackQueue* callbackQueue, ros::Publisher* publisherMotorCommandsGUI,*/ QWidget *parent = 0);
#endif
~MainGUIWindow();
#ifndef DEBUG_GUI
void init();
#endif
public slots:
#ifndef DEBUG_GUI
void runCallbacks();
#endif
private slots:
#ifndef DEBUG_GUI
// void PIDParamTableChanged(double param);
// void RateParamTableChanged(double param);
// void positionSetpointChanged(double param);
// void sampleTimeChanged(double param);
// void feedforwardCmdChanged(double cmd);
// void controllerTypeChanged(bool checked);
// void trajectoryTypeChanged(bool checked);
// void on_buttonStop_clicked();
// void on_buttonPrint_clicked();
// void on_buttonSetpointChange_clicked();
// void on_buttonPIDDefaultParams_clicked();
// void on_buttonSetpointCurrPos_clicked();
// void on_buttonDefaultFeedforward_clicked();
// void on_buttonResetMissed_clicked();
// void on_SetpointHome_clicked();
// void on_setpointZ200_clicked();
// void on_slideMotorCmdTest_valueChanged(int value);
// void on_buttonResetControllers_clicked();
// void on_buttonSetDefaultTs_clicked();
// void on_buttonSetDefaultRateParams_clicked();
// void on_slideRollAngleTest_valueChanged(int value);
// void on_slidePitchAngleTest_valueChanged(int value);
// void on_slideYawAngleTest_valueChanged(int value);
// void on_slideRollRateTest_valueChanged(int value);
// void on_slidePitchRateTest_valueChanged(int value);
// void on_slideYawRateTest_valueChanged(int value);
// void on_buttonStop_2_clicked();
#endif
void set_tabs(int n);
void transitionToMode(int mode);
void on_removeTable_clicked();
void on_radioButton_table_mode_toggled(bool checked);
void on_radioButton_crazyfly_zones_mode_toggled(bool checked);
void handleTablePiecesNumChanged(int newNum);
void on_radioButton_lock_mode_toggled(bool checked);
void on_checkBox_grid_toggled(bool checked);
void on_checkBox_table_toggled(bool checked);
void on_checkBox_crazyfly_zones_toggled(bool checked);
void on_tabWidget_currentChanged(int index);
void centerViewIndex(int index);
void on_pushButton_fitAll_clicked();
private:
Ui::MainGUIWindow *ui;
myGraphicsScene* scene;
QGraphicsRectItem* item1;
void _init();
#ifndef DEBUG_GUI
// void refreshScreen();
// callbacks
// void callbackControllerOutput(const crazypkg::ControllerOutputPackage& msg);
// void callbackViconData(const crazypkg::ViconData& msg);
// void callbackCntViconDataMissed(const std_msgs::Int32& msg);
void readDefaultParameters();
// void setDefaultPIDParameters();
// void setDefaultRateParameters();
// void setDefaultSampleTime();
// void setDefaultFeedforwardCmd();
// void initPIDParamsTable();
// void initRateParamsTable();
// void initPositionSetpoint();
// void initSampleTime();
// void initControllerType();
// void initFeedforwardCmd();
// void initSetpointQueues();
// void initSetpointType();
// void publishSetpoint();
// void updateSetpoint();
// void publishSampleTime(EControllerType controller);
ros::CallbackQueue m_CallbackQueue;
ros::NodeHandle* m_pNodeHandle;
// publishers
// ros::Publisher* m_pPublisherMotorCommandsGUI;
ros::Publisher* m_pPublisherControllerParam;
ros::Publisher* m_pPublisherPositionSetpoint;
ros::Publisher* m_pPublisherSampleTime;
ros::Publisher* m_pPublisherControllerType;
ros::Publisher* m_pPublisherDoSomething;
ros::Publisher* m_pPublisherFeedforwardCmd;
crazypkg::ControllerParam m_controllerParam;
crazypkg::PositionSetpoint m_positionSetpoint;
crazypkg::MotorCommands m_DummyCommands;
crazypkg::SampleTimeParam m_sampleTimeParam;
std_msgs::Int32 m_controllerType;
std_msgs::Int32 m_DoSomething;
crazypkg::MotorCommands m_feedforwardCmd;
//subscribers
ros::Subscriber* m_pSubscriberControllerOutput;
ros::Subscriber* m_pSubscriberViconData;
ros::Subscriber* m_pSubscriberCntViconDataMissed;
// crazypkg::MotorCommands m_MotorCommands;
// crazypkg::ViconData m_ViconData;
// params
// PIDParams m_PIDParams [countPIDControllers];
// default params
PIDParams m_DefaultPIDParams[countPIDControllers];
PIDParams m_DefaultRateParams[countRateControllers];
double m_DefaultSampleTime[countSampleTimeTypes];
crazypkg::MotorCommands m_DefaultFeedforwardCmd;
CSetpointQueue m_trajCircle;
CSetpointQueue m_trajSquare;
setpoint m_currSetpoint;
bool m_isStopButtonActive;
bool m_isCalActive;
enum ETrajectoryType
{
eTrajCustom,
eTrajCircle,
eTrajSquare
};
ETrajectoryType m_trajectoryType;
#endif
};
#endif // MAINGUIWINDOW_H
#ifndef MYGRAPHICSRECTITEM_H
#define MYGRAPHICSRECTITEM_H
#include <QGraphicsRectItem>
#include "cornergrabber.h"
class QGraphicsSceneMouseEvent;
class QPointF;
class QColor;
class myGraphicsRectItem : public QGraphicsRectItem
{
public:
explicit myGraphicsRectItem(const QRectF & rect, QGraphicsItem * parent = 0);
void lock();
void unlock();
public slots:
signals:
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
virtual void rectSizeChanged() = 0; // pure virtual function, has to be overridden in derived class
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
private:
void setCornerPositions();
bool anyGrabber();
int checkCornerGrabbers();
void createGrabbers();
bool grabbersAreCreated();
void deleteGrabbers();
QPen* pen;
QBrush* brush;
QRectF* tmp_rect;
QGraphicsRectItem* tmp_rect_item;
QPointF* p1;
QPointF* p2;
CornerGrabber* _bottomLeft_corner;
CornerGrabber* _topLeft_corner;
CornerGrabber* _topRight_corner;
CornerGrabber* _bottomRight_corner;
bool _grabbers_created;
bool resize_mode;
bool locked;
};
#endif
#ifndef MYGRAPHICSSCENE_H
#define MYGRAPHICSSCENE_H
#include <vector>
#include <QGraphicsScene>
#include "crazyFlyZone.h"
#include "tablePiece.h"
class QGraphicsSceneMouseEvent;
class QPointF;
class QColor;
class myGraphicsScene : public QGraphicsScene
{
Q_OBJECT
public:
explicit myGraphicsScene(QObject *parent = 0);
std::vector<crazyFlyZone*> crazyfly_zones;
std::vector<tablePiece*> table_pieces;
int getMode();
void setMode(int new_mode);
void setGrid(bool enable);
void hideTable();
void showTable();
void hideCrazyFlyZones();
void showCrazyFlyZones();
QRectF getRectFCrazyFlyZone(int index);
enum {mode_table, mode_crazyfly_zones, mode_locked};
void removeTable();
public slots:
void removeCrazyFlyZone(int index);
void setSelectedCrazyFlyZone(int index);
void changeModeTo(int next_mode);
signals:
void numCrazyFlyZonesChanged(int newNum);
void crazyFlyZoneSelected(int index);
void modeChanged(int mode);
void numTablePiecesChanged(int newNum);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
void keyPressEvent(QKeyEvent * keyEvent) override;
void drawBackground(QPainter *painter, const QRectF &rect);
private:
void lockTablePieces(void);
void unlockTablePieces(void);
void lockCrazyFlyZones(void);
void unlockCrazyFlyZones(void);
void addCrazyFlyZoneToVector(crazyFlyZone* rect);
void addTablePieceToVector(tablePiece* rect);
int checkSelectedCrazyFlyZone();
void updateIndexesAndLabelsCrazyFlyZones();
void removeTablePiece(int index);
QPen* pen;
QBrush* brush;
QRectF* tmp_rect;
crazyFlyZone* tmp_crazyfly_zone_item;
tablePiece* tmp_table_piece_item;
QPointF* p1;
QPointF* p2;
bool startedRect;
int mode;
bool grid_enable;
};
#endif
#ifndef MYGRAPHICSVIEW_H
#define MYGRAPHICSVIEW_H
#include <vector>
#include <QGraphicsView>
#include <QWheelEvent>
class myGraphicsView : public QGraphicsView
{
Q_OBJECT
public:
explicit myGraphicsView(QWidget *parent = 0);
public slots:
signals:
protected:
void mousePressEvent(QMouseEvent *mouseEvent) override;
void mouseMoveEvent(QMouseEvent *mouseEvent) override;
void mouseReleaseEvent(QMouseEvent *mouseEvent) override;
virtual void wheelEvent(QWheelEvent* event) override; // TODO: right now, do it in the whole MainGUIWindow. Afterwards maybe do this only in the QGraphicsScene (need to do own class)
private:
bool translation_mode;
qreal translate_dx;
qreal translate_dy;
QPointF* tmp_point