#include <gui_canvas.h>
Definiert in Zeile 18 der Datei gui_canvas.h.
Öffentliche Methoden | |
void | moveRobot (int _row, int _col) |
MyCanvasView (QWidget *parent=0, const char *name=0) | |
MyCanvasView (QCanvas *c, QWidget *parent=0, const char *name=0, WFlags f=0) | |
void | setDimension (int _rows, int _cols, int _initRow, int _initCol) |
Private Methoden | |
void | initCanvas () |
void | paintBottom () |
Private Attribute | |
QCanvasSprite * | base |
QCanvasPixmapArray * | base_pix |
QCanvasRectangle * | bottom |
QCanvas * | canvas |
int | distance |
QCanvasText * | distanceText |
QCanvasSprite * | frame |
QCanvasPixmapArray * | frame_pix |
QCanvasSprite * | holder |
QCanvasPixmapArray * | holder_pix |
int | iCols |
int | iRows |
QPoint | oldPos |
QCanvasText * | posText |
Statische private Attribute | |
static const int | base_beam_height = 20 |
static const int | base_beam_width = 36 |
static const int | base_inner_height = base_total_height - base_beam_height - stand_beam_height |
static const int | base_total_height = 200 |
static const int | base_total_width = 170 |
static const int | bottom_start_y |
static const int | bottom_width = stand_total_width + (stand_inner_width - base_total_width) |
static const int | canvas_height = 400 |
static const int | canvas_width = 460 |
static const int | holder_total_height = 29 |
static const int | holder_total_width = 46 |
static const int | stand_beam_height = 15 |
static const int | stand_beam_width = 15 |
static const int | stand_inner_height = stand_total_height - (2*stand_beam_height) |
static const int | stand_inner_width = stand_total_width - (2*stand_beam_width) - base_total_width |
static const int | stand_total_height = 118 |
static const int | stand_total_width = 330 |
MyCanvasView::MyCanvasView | ( | QCanvas * | c, | |
QWidget * | parent = 0 , |
|||
const char * | name = 0 , |
|||
WFlags | f = 0 | |||
) | [inline] |
Definiert in Zeile 22 der Datei gui_canvas.h.
Benutzt canvas und initCanvas().
00022 : QCanvasView( c, parent, name, f ) { 00023 canvas = c; 00024 initCanvas(); 00025 }
MyCanvasView::MyCanvasView | ( | QWidget * | parent = 0 , |
|
const char * | name = 0 | |||
) | [inline] |
Definiert in Zeile 27 der Datei gui_canvas.h.
Benutzt canvas, canvas_height, canvas_width und initCanvas().
00027 : QCanvasView( parent, name, 0 ) { 00028 canvas = new QCanvas(canvas_width, canvas_height); 00029 initCanvas(); 00030 }
void MyCanvasView::initCanvas | ( | ) | [private] |
This function initialize the Canvas and set all Object to the basic position 0,0
Definiert in Zeile 6 der Datei gui_canvas.cpp.
Benutzt base, base_pix, BASEPIX, bottom_start_y, canvas, distance, distanceText, frame, frame_pix, FRAMEPIX, holder, holder_pix, HOLDERPIX, moveRobot(), paintBottom(), posText und setDimension().
Wird benutzt von MyCanvasView().
00006 { 00007 this->setCanvas (canvas); 00008 00009 // set covered distance to 0 00010 this->distance = 0; 00011 00012 // draw Bottom first 00013 this->paintBottom(); 00014 00015 // load Pictures 00016 this->frame_pix = new QCanvasPixmapArray (FRAMEPIX, 0); 00017 if(!this->frame_pix->isValid()){ 00018 cout << "Could not load pix: " << FRAMEPIX << endl; 00019 } 00020 this->base_pix = new QCanvasPixmapArray (BASEPIX, 0); 00021 if(!this->base_pix->isValid()){ 00022 cout << "Could not load pix: " << BASEPIX << endl; 00023 } 00024 this->holder_pix = new QCanvasPixmapArray (HOLDERPIX, 0); 00025 if(!this->holder_pix->isValid()){ 00026 cout << "Could not load pix: " << HOLDERPIX << endl; 00027 } 00028 00029 // create CanvasSprite 00030 this->frame = new QCanvasSprite (this->frame_pix, canvas); 00031 this->base = new QCanvasSprite (this->base_pix, canvas); 00032 this->holder = new QCanvasSprite (this->holder_pix, canvas); 00033 00034 // create Text-LAbel 00035 this->distanceText = new QCanvasText ("distance travelled: " + QString::number(this->distance), canvas); 00036 this->distanceText->move(10, bottom_start_y + 10); 00037 this->posText = new QCanvasText ("robot state: {x,y} = {2,2}", canvas); 00038 this->posText->move(10, bottom_start_y + 30); 00039 00040 00041 // at least set to position 0,0 00042 this->setDimension (5, 5, 3, 3); 00043 this->moveRobot(3, 3); 00044 00045 // add remaining elements 00046 this->holder->show(); 00047 this->distanceText->show(); 00048 this->posText->show(); 00049 this->base->show(); 00050 this->frame->show(); 00051 00052 00053 // draw Canvas 00054 this->canvas->update(); 00055 00056 }
void MyCanvasView::moveRobot | ( | int | _row, | |
int | _col | |||
) |
This function pitch the Objects(Frame, stand, holder) to a position
_row | ||
_col |
Definiert in Zeile 63 der Datei gui_canvas.cpp.
Benutzt base, base_inner_height, base_total_height, base_total_width, bottom_start_y, canvas, distance, distanceText, frame, holder, holder_total_height, holder_total_width, iCols, iRows, oldPos, posText, stand_beam_height, stand_beam_width, stand_inner_width und stand_total_height.
Wird benutzt von initCanvas(), setDimension() und Simulation::simulationWalk().
00063 { 00064 00065 QPoint rpos, spos, hpos; 00066 float pixX, pixY; 00067 00068 _row--; 00069 _col--; 00070 00071 // Calculate pixel for one Step on the x and y axis 00072 pixX = stand_inner_width / (float)iCols; 00073 pixY = base_inner_height / (float)iRows; 00074 00075 /********************************************** 00076 // set frame and base position: 00077 // ===================== 00078 // - if _row < 1/2*iRows, 00079 // frame move up 00080 // - if _row >= 1/2*iRows, then 00081 // base move up 00082 **********************************************/ 00083 // frame X-Position 00084 rpos.setX((int)(_col * pixX)); 00085 // base X-Position 00086 spos.setX((int)(stand_beam_width + rpos.x() + (pixX * (float)(iCols - _col)))); 00087 00088 // frame up and base on the bottom 00089 if (_row <= (0.5 * (float)(iRows))) { 00090 00091 // base Y-Position 00092 spos.setY((int)(bottom_start_y - base_total_height)); 00093 00094 // frame Y-Position 00095 rpos.setY((int)(spos.y() + (float)(_row * pixY))); 00096 00097 // base up and frame on the bottom 00098 } else { 00099 00100 // frame Y-Position 00101 rpos.setY((int)(bottom_start_y - stand_total_height)); 00102 00103 // base Y-Position 00104 spos.setY((int)(rpos.y() - (float)(_row * pixY)) +1); 00105 00106 // the base can get a new x-position if its up. Therefore the textlabel and the distance must be updated 00107 if (_col != this->oldPos.x()) { 00108 distance += this->oldPos.x() - _col; 00109 this->distanceText->setText("distance travelled: " + QString::number(this->distance)); 00110 } 00111 } 00112 00113 // Position of the red holder 00114 hpos.setX((int)( spos.x() + (base_total_width/2) - (holder_total_width/2) )); 00115 hpos.setY((int)( rpos.y() - (holder_total_height/2) + (stand_beam_height/2) )); 00116 00117 // calculate new stand-Position 00118 this->frame->move(rpos.x(), rpos.y()); 00119 this->base->move(spos.x(), spos.y()); 00120 this->holder->move(hpos.x(), hpos.y()); 00121 // update Position-Label 00122 this->posText->setText("robot state: {x,y} = {" + 00123 QString::number(_col+1) + "," + QString::number(_row+1) + "}"); 00124 00125 this->canvas->update(); 00126 00127 // save position 00128 this->oldPos.setX(_col); 00129 this->oldPos.setY(_row); 00130 }
void MyCanvasView::paintBottom | ( | ) | [private] |
This function draw the bottom
Definiert in Zeile 136 der Datei gui_canvas.cpp.
Benutzt bottom, bottom_start_y, canvas, canvas_height und canvas_width.
Wird benutzt von initCanvas().
00136 { 00137 00138 this->bottom = new QCanvasRectangle (0, bottom_start_y, canvas_width, canvas_height, this->canvas); 00139 this->bottom->setBrush( QColor(200,200,200) ); 00140 this->bottom->show(); 00141 }
void MyCanvasView::setDimension | ( | int | _rows, | |
int | _cols, | |||
int | _initRow, | |||
int | _initCol | |||
) |
Diese Funktion, setzt die Anzahl der maximalen Zeilen und Spalten, damit die Zwischenzustände bestimmt werden können.
_rows | ||
_cols | ||
_initRow | ||
_initCol |
Definiert in Zeile 152 der Datei gui_canvas.cpp.
Benutzt distance, distanceText, iCols, iRows, moveRobot() und oldPos.
Wird benutzt von Simulation::apply_button_clicked(), initCanvas() und Simulation::start_simulation_clicked().
00152 { 00153 00154 _rows--; 00155 _cols--; 00156 _initRow--; 00157 _initCol--; 00158 00159 this->iRows = _rows; 00160 this->iCols = _cols; 00161 00162 // Weg mit 0 initialisieren 00163 this->distance = 0; 00164 this->distanceText->setText("distance travelled: " + QString::number(this->distance)); 00165 00166 // Initialposition einnehmen 00167 this->moveRobot(_initRow, _initCol); 00168 00169 // Diese initial-Position als aktuelle Position speichern 00170 this->oldPos.setX(_initCol); 00171 this->oldPos.setY(_initRow); 00172 }
QCanvasSprite * MyCanvasView::base [private] |
const int MyCanvasView::base_beam_height = 20 [static, private] |
Definiert in Zeile 55 der Datei gui_canvas.h.
const int MyCanvasView::base_beam_width = 36 [static, private] |
Definiert in Zeile 54 der Datei gui_canvas.h.
const int MyCanvasView::base_inner_height = base_total_height - base_beam_height - stand_beam_height [static, private] |
QCanvasPixmapArray * MyCanvasView::base_pix [private] |
const int MyCanvasView::base_total_height = 200 [static, private] |
const int MyCanvasView::base_total_width = 170 [static, private] |
QCanvasRectangle* MyCanvasView::bottom [private] |
const int MyCanvasView::bottom_start_y [static, private] |
Initialisierung:
Definiert in Zeile 64 der Datei gui_canvas.h.
Wird benutzt von initCanvas(), moveRobot() und paintBottom().
const int MyCanvasView::bottom_width = stand_total_width + (stand_inner_width - base_total_width) [static, private] |
Definiert in Zeile 67 der Datei gui_canvas.h.
QCanvas* MyCanvasView::canvas [private] |
Definiert in Zeile 37 der Datei gui_canvas.h.
Wird benutzt von initCanvas(), moveRobot(), MyCanvasView() und paintBottom().
const int MyCanvasView::canvas_height = 400 [static, private] |
const int MyCanvasView::canvas_width = 460 [static, private] |
int MyCanvasView::distance [private] |
Definiert in Zeile 70 der Datei gui_canvas.h.
Wird benutzt von initCanvas(), moveRobot() und setDimension().
QCanvasText* MyCanvasView::distanceText [private] |
Definiert in Zeile 41 der Datei gui_canvas.h.
Wird benutzt von initCanvas(), moveRobot() und setDimension().
QCanvasSprite* MyCanvasView::frame [private] |
QCanvasPixmapArray* MyCanvasView::frame_pix [private] |
QCanvasSprite * MyCanvasView::holder [private] |
QCanvasPixmapArray * MyCanvasView::holder_pix [private] |
const int MyCanvasView::holder_total_height = 29 [static, private] |
const int MyCanvasView::holder_total_width = 46 [static, private] |
int MyCanvasView::iCols [private] |
int MyCanvasView::iRows [private] |
QPoint MyCanvasView::oldPos [private] |
QCanvasText * MyCanvasView::posText [private] |
const int MyCanvasView::stand_beam_height = 15 [static, private] |
const int MyCanvasView::stand_beam_width = 15 [static, private] |
const int MyCanvasView::stand_inner_height = stand_total_height - (2*stand_beam_height) [static, private] |
Definiert in Zeile 61 der Datei gui_canvas.h.
const int MyCanvasView::stand_inner_width = stand_total_width - (2*stand_beam_width) - base_total_width [static, private] |
const int MyCanvasView::stand_total_height = 118 [static, private] |
const int MyCanvasView::stand_total_width = 330 [static, private] |
Definiert in Zeile 47 der Datei gui_canvas.h.