Commit 76810876 authored by Olivier Lagrasse's avatar Olivier Lagrasse
Browse files

- Events are available again for render and export.

- Add color for events.
- Change QPainter by QGLWidget::renderText in Render_opengl.cpp.
parent dd6bf6cf
......@@ -112,8 +112,8 @@ Geometry::Geometry(){
_z_container_under = -1.2;
_z_ruler = -0.5;
_z_ruler_under = -0.6;
_z_arrow = -2.0;/* closer to camera than containers or states (MUST be negative)*/
_z_event = -3.0;/* closer to camera than containers or states (MUST be negative)*/
_z_arrow = -3.0;/* closer to camera than containers or states (MUST be negative)*/
_z_event = -2.0;/* closer to camera than containers or states (MUST be negative)*/
_z_counter = -4.0;
_z_state = -5.0;
......
......@@ -333,10 +333,10 @@ public:
inline void end_draw_arrows(){
drawing_instance->end_draw_arrows();
}
/*
inline void start_draw_events(){
drawing_instance->start_draw_events();
}*/
}
/*!
* \brief Draw an event.
......@@ -346,16 +346,18 @@ public:
*
* This function stores all the information of the event to display it each time the render area need to be updated.
*/
inline void draw_event(Element_pos time, Element_pos height, Element_pos container_height){
inline void draw_event(Element_pos time, Element_pos height, Element_pos container_height, const Element_col r, const Element_col g, const Element_col b){
/* For SVG */
Element_pos radius;/* the circle radius */
drawing_instance->set_color(r, g, b);
time = trace_to_render_x(time);
height = trace_to_render_y(height);
container_height = container_height*coeff_trace_render_y();
radius = 0.3f;
radius = .5f;
drawing_instance->draw_circle(time, height, _z_event, radius);
drawing_instance->draw_line(time, height,
......@@ -364,10 +366,10 @@ public:
/* For OpenGL */
drawing_instance->draw_event(time, height, container_height);
}
/*
inline void end_draw_events(){
drawing_instance->end_draw_events();
}*/
}
/*!
* \brief Creates and opens the display list for counter draws.
......
......@@ -76,7 +76,7 @@ static bool _draw_arrow;/* Yes, it is global, but also it is static. In fact, it
the Render_opengl class. */
static bool _draw_circle;/* Yes, it is global, but also it is static. In fact, it is used to
static bool _draw_event;/* Yes, it is global, but also it is static. In fact, it is used to
check the circle drawing state. It is not an attribute of
the Render_opengl class. */
......@@ -302,6 +302,8 @@ void Render_opengl::paintGL(){
Element_pos old_x, old_y, new_x, new_y;
old_x = _mouse_x*(Info::Render::width/Info::Screen::width);
old_y = Info::Render::height - _mouse_y*(Info::Render::height/Info::Screen::height);
new_x = _new_mouse_x*(Info::Render::width/Info::Screen::width);
......@@ -362,21 +364,36 @@ void Render_opengl::resizeOverlayGL(int width, int height){
void Render_opengl::paintOverlayGL (){
*/
// cerr << __FILE__ << " " << __LINE__ << " PLOP" << endl;
QPainter painter(this);
// QPainter painter(this);
//painter.setPen(Qt::NoPen);
//painter.setBrush(QColor(125, 125, 150));
//painter.drawRect(Info::Screen::width-210, Info::Screen::height-40, 200, 30);
QFont arial_font = QFont("Arial", 10);
qglColor(Qt::white);//QColor(0, 0, 0));
/*
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::white);
painter.setFont(QFont("Arial", 10));
*/
/* Draw container text */
for (unsigned int i=0 ; i<_texts.size() ; i++){
painter.drawText( render_to_screen_x(_texts[i].x * _x_scale_container_state/0.20),
render_to_screen_y( trace_to_render_y(_texts[i].y) + 0.5),/* '+ 0.5' is used to center text vertically. */
_texts[i].value.c_str());/* prvent this, need to construct Qstring every frames for every texts! */
renderText ( render_to_screen_x(_texts[i].x * _x_scale_container_state/0.20),
render_to_screen_y( trace_to_render_y(_texts[i].y) + 0.5),
_texts[i].value.c_str(),
arial_font);
// painter.drawText( render_to_screen_x(_texts[i].x * _x_scale_container_state/0.20),
// render_to_screen_y( trace_to_render_y(_texts[i].y) + 0.5),/* '+ 0.5' is used to center text vertically. */
// _texts[i].value.c_str());/* prvent this, need to construct Qstring every frames for every texts! */
}
/* Draw ruler text */
......@@ -386,34 +403,40 @@ void Render_opengl::paintOverlayGL (){
graduation_diff = Ruler::get_graduation_diff(Info::Render::_x_min_visible, Info::Render::_x_max_visible);
coeff_prefix = Ruler::get_coeff_for_common_prefix(Info::Render::_x_min_visible, Info::Render::_x_max_visible);
painter.setFont(QFont("Arial", 14));
// painter.setFont(QFont("Arial", 14));
arial_font.setPointSize(14);
buf_txt.str("");/* flush the buffer */
buf_txt << "min: " << (double)Info::Render::_x_min_visible;
painter.drawText(render_to_screen_x(trace_to_render_x(Info::Render::_x_min_visible)),
render_to_screen_y(3),
buf_txt.str().c_str());
renderText (render_to_screen_x(trace_to_render_x(Info::Render::_x_min_visible)),
render_to_screen_y(3),
buf_txt.str().c_str(),
arial_font);
buf_txt.str("");/* flush the buffer */
buf_txt << "max: " << (double)Info::Render::_x_max_visible;
painter.drawText(render_to_screen_x(trace_to_render_x(Info::Render::_x_max_visible))-130,
render_to_screen_y(3),
buf_txt.str().c_str());
renderText (render_to_screen_x(trace_to_render_x(Info::Render::_x_max_visible))-130,
render_to_screen_y(3),
buf_txt.str().c_str(),
arial_font);
buf_txt.str("");
buf_txt << (double)Ruler::get_common_part(Info::Render::_x_min_visible, coeff_prefix) << "--";
painter.drawText( render_to_screen_x(
trace_to_render_x(
(Info::Render::_x_min_visible +
Info::Render::_x_max_visible) / 2)),
render_to_screen_y(3),
buf_txt.str().c_str());
renderText (render_to_screen_x(
trace_to_render_x(
(Info::Render::_x_min_visible +
Info::Render::_x_max_visible) / 2)),
render_to_screen_y(3),
buf_txt.str().c_str(),
arial_font);
painter.setFont(QFont("Arial", 10));
// painter.setFont(QFont("Arial", 10));
arial_font.setPointSize(10);
for (Element_pos i = Info::Render::_x_min_visible ;
i < Info::Render::_x_max_visible ;
......@@ -422,9 +445,10 @@ void Render_opengl::paintOverlayGL (){
buf_txt.str("");/* flush the buffer */
buf_txt << Ruler::get_variable_part(i, coeff_prefix, 2);
painter.drawText(render_to_screen_x(trace_to_render_x(i)+1),
render_to_screen_y(8),
buf_txt.str().c_str());
renderText (render_to_screen_x(trace_to_render_x(i)+1),
render_to_screen_y(8),
buf_txt.str().c_str(),
arial_font);
}
......@@ -437,7 +461,7 @@ void Render_opengl::paintOverlayGL (){
*/
painter.end();
// painter.end();
}
......@@ -821,6 +845,8 @@ void Render_opengl::set_color(float r, float g, float b){
_red = r;
_green = g;
_blue = b;
glColor3d(_red, _green, _blue);
}
void Render_opengl::draw_text(const Element_pos x, const Element_pos y, const Element_pos, const std::string s){
......@@ -862,7 +888,7 @@ void Render_opengl::draw_triangle(Element_pos , Element_pos ,
}
void Render_opengl::draw_line(Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2, Element_pos z){
if (_draw_ruler || _draw_arrow || _draw_circle) return;/* do not draw line for ruler or for arrow or for circle */
if (_draw_ruler || _draw_arrow || _draw_event) return;/* do not draw line for ruler or for arrow or for event */
const Element_pos offset_x = -_default_entity_x_translate;
......@@ -897,7 +923,7 @@ void Render_opengl::start_draw(){
_draw_ruler = false;
_draw_container = false;
_draw_arrow = false;
_draw_circle = false;
_draw_event = false;
}
......@@ -964,18 +990,30 @@ void Render_opengl::end_draw_arrows(){
_draw_arrow = false;
}
void Render_opengl::start_draw_events(){
_draw_event = true;
}
void Render_opengl::draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height){
Circle_ buf;
Event_ buf;
const Element_pos offset_x = -_default_entity_x_translate;
const Element_pos offset_y = -_ruler_y - _ruler_height;
buf.time = time + offset_x;
buf.height = height + offset_y;
buf.container_height = container_height + offset_y;
buf.red = _red;
buf.green = _green;
buf.blue = _blue;
_circles.push_back(buf);
}
void Render_opengl::end_draw_events(){
_draw_event = false;
}
void Render_opengl::start_draw_counter(){
}
......@@ -1066,7 +1104,7 @@ void Render_opengl::draw_stored_arrows(){
glBegin(GL_TRIANGLES);
{
glColor3d(_red, _green, _blue);
// glColor3d(_red, _green, _blue);
glVertex2d(0.0, 0.0);
glVertex2d(-1.2, -0.4);
glVertex2d(-1.2, 0.4);
......@@ -1099,32 +1137,79 @@ void Render_opengl::draw_stored_circles(){
const int step = 20;/* 20 polygons for the circle */
const float angle = M_PI/2.0f;
const float delta_angle = 2*M_PI/step;
const float radius = 0.3f;
const float radius = .5f;
set_color(1, 1, 1);
const unsigned int size = _circles.size();
// std::cerr << __FILE__ << __LINE__<< " " << size << std::endl;
// return;/* Stack overflow... Why? */
for (unsigned int i=0 ; i<size ; i++){
/* Draw the circle */
glBegin(GL_POLYGON);
/*
time = _circles[i].time;
height = _circles[i].height;
container_height = _circles[i].container_height;
*/
// std::cerr << __FILE__ << __LINE__<< " " << _circles[i].time << " " << _circles[i].height << std::endl;
glPushMatrix();
{
glColor3d(_red, _green, _blue);
for(int i = 0 ; i < step ; i ++){
glVertex3d(_circles[i].time + cos(angle+delta_angle*i)*radius ,
_circles[i].height + sin(angle+delta_angle*i)*radius ,
_z_event);
set_color(1.0 - _circles[i].red, 1.0 - _circles[i].green, 1.0 - _circles[i].blue);
glTranslated(_default_entity_x_translate - _x_state_translate,
_ruler_y + _ruler_height - _y_state_translate,
_z_arrow);
glScalef(_x_state_scale, _y_state_scale, 1.0);
/* Draw the circle */
glBegin(GL_POLYGON);
{
for(int j = 0 ; j < step ; j ++){
glVertex2d(_circles[i].time + cos(angle+delta_angle*j)*radius/_x_state_scale,
_circles[i].height + sin(angle+delta_angle*j)*(radius/_y_state_scale)*Info::Screen::width/Info::Screen::height);
}
}
glEnd();
set_color(_circles[i].red, _circles[i].green, _circles[i].blue);
/* Draw the sub-circle */
glBegin(GL_POLYGON);
{
for(int j = 0 ; j < step ; j ++){
glVertex3d(_circles[i].time + cos(angle+delta_angle*j)*radius/(1.2*_x_state_scale) ,
_circles[i].height + sin(angle+delta_angle*j)*radius/(1.2*_y_state_scale)*Info::Screen::width/Info::Screen::height ,
0.1);
}
}
glEnd();
glLineWidth( 3.0 );
/* Draw the line */
glBegin(GL_LINES);
{
glVertex2d(_circles[i].time, _circles[i].height);
glVertex2d(_circles[i].time, _circles[i].height+_circles[i].container_height);
}
}
glEnd();
glEnd();
glLineWidth( 1.0 );
/* Draw the line */
glBegin(GL_LINES);
{
glVertex2d(_circles[i].time, _circles[i].height);
glVertex2d(_circles[i].time, _circles[i].height+_circles[i].container_height);
}
glEnd();
glPopMatrix();
}
set_color(1.0, 1.0, 1.0);
}
......@@ -66,17 +66,24 @@ struct Arrow_{
* \brief Coordinates.
*/
Element_pos start_time, end_time, start_height, end_height;
/*!
* \brief Colors.
*/
Element_col red, green, blue;
};
/*!
* \brief Structure used to store circle information.
* \brief Structure used to store event information.
*/
struct Circle_{
struct Event_{
/*!
* \brief Coordinates and radius.
*/
Element_pos time, height, container_height;
/*!
* \brief Colors.
*/
Element_col red, green, blue;
};
......@@ -125,7 +132,7 @@ protected:
std::vector<Container_text_> _texts;
std::vector<Arrow_> _arrows;
std::vector<Circle_> _circles;
std::vector<Event_> _circles;
/***********************************
......@@ -327,6 +334,8 @@ public:
*/
// void draw_stored_arrows(std::vector<Arrow_> &arrows);
void start_draw_events();
/*!
* \brief Draw an event.
* \param time time when the event occurs.
......@@ -340,6 +349,9 @@ public:
*/
void draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height);
void end_draw_events();
/*!
* \brief Draw events contained in the Event_ vector
* \param events An event vector.
......
......@@ -118,7 +118,6 @@ void Render_svg::draw_text(const Element_pos x, const Element_pos y, const Eleme
void Render_svg::draw_quad(Element_pos x, Element_pos y, Element_pos , Element_pos w, Element_pos h){
// const Element_pos x_min = trace_to_render_x(Info::Render::_x_min_visible);
// const Element_pos x_max = trace_to_render_x(Info::Render::_x_max_visible);
......@@ -175,9 +174,10 @@ void Render_svg::draw_circle(Element_pos x, Element_pos y, Element_pos , Element
_buffer.str("");
_buffer << "<circle"
<< " cx=\"" << render_to_screen_x(x) << "\""
<< " cy=\"" << render_to_screen_x(y) << "\""
<< " cy=\"" << render_to_screen_y(y) << "\""
<< " r=\"" << max(render_to_screen_x(r), render_to_screen_y(r)) << "\""
<< " style=\"fill:yellow\""
<< " fill=\"rgb(" << floor(_red*256) << "," << floor(_green*256) << "," << floor(_blue*256) << ")\""/* TODO: choice better scale than '*256' */
<< " stroke=\"rgb(" << floor((1.0-_red)*256) << "," << floor((1.0-_green)*256) << "," << floor((1.0-_blue)*256) << ")\""/* TODO: choice better scale than '*256' */
<< "/>\n";
_output_file.write(_buffer.str().c_str(), _buffer.str().size());
......@@ -228,9 +228,15 @@ void Render_svg::draw_arrow(const Element_pos , const Element_pos , const Elemen
void Render_svg::end_draw_arrows(){
}
void Render_svg::start_draw_events(){
}
void Render_svg::draw_event(const Element_pos , const Element_pos , const Element_pos ){
}
void Render_svg::end_draw_events(){
}
void Render_svg::start_draw_counter(){
}
......
......@@ -173,6 +173,8 @@ public:
*/
// void draw_stored_arrows(std::vector<Arrow_> &arrows);
void start_draw_events();
/*!
* \brief Draw an event.
* \param time time when the event occurs.
......@@ -186,6 +188,7 @@ public:
*/
void draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height);
void end_draw_events();
/*!
* \brief Draw events contained in the Event_ vector
* \param events An event vector.
......
......@@ -370,6 +370,7 @@ public:
lvl_zoom = 0;
draw_object->start_draw_states();
draw_object->start_draw_events();
for (std::list<const Container *>::const_iterator c = _entity_containers.begin();
c != _entity_containers.end();
c++) {
......@@ -393,6 +394,7 @@ public:
}
}/* end for (!_stack_states.empty()) */
draw_object->end_draw_events();
draw_object->end_draw_states();
......
......@@ -129,9 +129,9 @@ public:
* \brief Draw an event
* \param time Time of the event
*/
inline void draw_event(double time) {
inline void draw_event(double time, double r, double g, double b) {
Element_pos y = _position*(_container_height+_container_v_space) + _container_v_space/2;
_draw_object->draw_event(time, y, _state_height);
_draw_object->draw_event(time, y, _state_height, r, g, b);
}
/*!
......@@ -171,7 +171,26 @@ struct DrawNode<D, Event> {
b=true;
i++;
draw->draw_event(node->get_element()->get_time().get_value());
std::map<std::string, Value *>::const_iterator field;
const Event *event = node->get_element();
const std::map<std::string, Value *> *extra_fields;
const Color *color;
extra_fields = event->get_value()->get_extra_fields();
// Search the color
if (event->get_value() &&
!event->get_value()->get_extra_fields()->empty() &&
((field = event->get_value()->get_extra_fields()->find(std::string("Color"))) != extra_fields->end())) {
/* Call the object event drawing function with the event color */
color = (const Color *)(*field).second;
draw->draw_event(node->get_element()->get_time().get_value(),
color->get_red(), color->get_green(), color->get_blue());
}else{
/* Call the object event drawing function with default color */
draw->draw_event(node->get_element()->get_time().get_value(),
1.0, 1.0, 1.0);
}
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment