diff --git a/include/turtlesim/turtle_frame.h b/include/turtlesim/turtle_frame.h index c6873ee7016ac31cb4140f55b5ad9a5c1236dd6b..0ddd09413ef692eec96a4c321895c1fc8f6c377a 100644 --- a/include/turtlesim/turtle_frame.h +++ b/include/turtlesim/turtle_frame.h @@ -59,6 +59,9 @@ public: std::string spawnTurtle(const std::string& name, float x, float y, float angle); std::string spawnTurtle(const std::string& name, float x, float y, float angle, size_t index); + void setShape(std::string shape); + void drawShape(); + protected: void paintEvent(QPaintEvent* event); @@ -99,6 +102,8 @@ private: float meter_; float width_in_meters_; float height_in_meters_; + + std::string shape; }; } diff --git a/src/turtle_frame.cpp b/src/turtle_frame.cpp index 60f4551ef9d022d52fb044e1e5e7631c7c4bddf6..37d3f41dfc12da953fd9c91f0fed937a0a69db8e 100644 --- a/src/turtle_frame.cpp +++ b/src/turtle_frame.cpp @@ -44,7 +44,10 @@ namespace turtlesim { -TurtleFrame::TurtleFrame(QWidget* parent, Qt::WindowFlags f) +TurtleFrame::TurtleFrame(QWidget* parent, Qt::WindowFlags f): + TurtleFrame("rectangle", parent, f) {} + +TurtleFrame::TurtleFrame(std::string shape, QWidget* parent, Qt::WindowFlags f) : QFrame(parent, f) , path_image_(FRAME_WIDTH, FRAME_HEIGHT, QImage::Format_ARGB32) , path_painter_(&path_image_) @@ -75,7 +78,7 @@ TurtleFrame::TurtleFrame(QWidget* parent, Qt::WindowFlags f) { private_nh_.setParam("background_b", DEFAULT_BG_B); } - + QVector<QString> turtles; // turtles.append("box-turtle.png"); // turtles.append("robot-turtle.png"); @@ -92,7 +95,7 @@ TurtleFrame::TurtleFrame(QWidget* parent, Qt::WindowFlags f) // turtles.append("jade.png"); // turtles.append("kinetic.png"); // turtles.append("lunar.png"); - //turtles.append("melodic.png"); + // turtles.append("melodic.png"); // turtles.append("noetic.png"); QString images_path = (ros::package::getPath("turtlesim_xl") + "/images/").c_str(); for (int i = 0; i < turtles.size(); ++i) @@ -294,4 +297,28 @@ bool TurtleFrame::resetCallback(std_srvs::Empty::Request&, std_srvs::Empty::Resp return true; } +void TurtleFrame::drawShape() { + path_painter_.setPen(QColor(0xff,0xff,0xff)); + int xTurtleStart = 12*meter_; + int yTurtleStart = FRAME_HEIGHT - 7*meter_; + if(shape == "triangle") { + int xTopRight = xTurtleStart; + int xTopLeft = xTopRight/2; + int xBottom = (xTopLeft + xTopRight) / 2; + + int yTop = yTurtleStart; + int yBottom = yTop + 5*meter_; + + path_painter_.drawLine(xTopLeft, yTop, xTopRight, yTop); + path_painter_.drawLine(xTopLeft, yTop, xBottom, yBottom); + path_painter_.drawLine(xBottom, yBottom, xTopRight, yTop); + }else { + path_painter_.drawRect((12-5)*meter_,FRAME_HEIGHT-(7-5)*meter_,5*meter_,-5*meter_); + } +} + +void TurtleFrame::setShape(std::string shape) { + this->shape = shape; +} + } diff --git a/src/turtlesim_xl.cpp b/src/turtlesim_xl.cpp index 1d5cac146ffd4c31297076fbf16105dc2c56a9cc..681c396117dd3b6933a60f9881926b8424c9076c 100644 --- a/src/turtlesim_xl.cpp +++ b/src/turtlesim_xl.cpp @@ -45,9 +45,11 @@ public: nh_.reset(new ros::NodeHandle); } - int exec() + int exec(std::string shape = "rectangle") { turtlesim::TurtleFrame frame; + frame.setShape(shape); + frame.drawShape(); frame.show(); return QApplication::exec(); @@ -56,7 +58,15 @@ public: int main(int argc, char** argv) { + /* + argv with launch file: + 0: path to node + 1: additional argument (the result of shape=... in this case) + 2: name of the node + 3: path to log + */ TurtleApp app(argc, argv); - return app.exec(); + std::string shape = argv[1]; + return app.exec(shape); }