Commit f9f9eb38 authored by Olivier Lagrasse's avatar Olivier Lagrasse

add color for links

parent c9f913bd
......@@ -286,7 +286,6 @@ public:
*/
inline void start_draw_arrows(){
drawing_instance->start_draw_arrows();
drawing_instance->set_color(1, 1, 1);
}
/*!
......@@ -298,13 +297,15 @@ public:
*
* This function stores all the information of the arrow to display it each time the render area need to be updated.
*/
inline void draw_arrow(Element_pos start_time, Element_pos end_time, Element_pos start_height, Element_pos end_height){
inline void draw_arrow(Element_pos start_time, Element_pos end_time, Element_pos start_height, Element_pos end_height, const Element_col r, const Element_col g, const Element_col b){
/* For SVG */
const Element_pos triangle_size = 2.0;
const Element_pos coeff = 180.0f/M_PI;
Element_pos angle;
drawing_instance->set_color(r, g, b);
start_time = trace_to_render_x(start_time);
end_time = trace_to_render_x(end_time);
start_height = trace_to_render_y(start_height);
......@@ -321,7 +322,9 @@ public:
end_time, end_height, _z_arrow);
/* For OpenGL */
drawing_instance->draw_arrow(start_time, end_time, start_height, end_height);
drawing_instance->draw_arrow(start_time, end_time, start_height, end_height, r, g, b);
drawing_instance->set_color(1, 1, 1);/* init */
}
/*!
......@@ -330,6 +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.
......@@ -357,6 +364,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.
......
......@@ -649,15 +649,15 @@ void Render_opengl::call_ruler(){
//return;
/* Now, draw ruler */
float common_part;
float variable_part;
// float common_part;
// float variable_part;
Element_pos graduation_diff;
Element_pos coeff_prefix;
// std::ostringstream buf_txt;
const Element_pos offset_x = _default_entity_x_translate;
const Element_pos offset_y = _ruler_y + _ruler_height+3.5;
// QLabel* ui;
int count;
// int count;
/*
QPainter painter(this);
......@@ -680,7 +680,7 @@ void Render_opengl::call_ruler(){
count!=2
;
count++,
ui = Info::Render::_ui_render_max_value,
ui = Info::Render::_ui_render_max_value,
buf_txt.str(""),// flush the buffer
common_part = Ruler::get_common_part(Info::Render::_x_max_visible, coeff_prefix),
variable_part = Ruler::get_variable_part(Info::Render::_x_max_visible, coeff_prefix, 2)
......@@ -877,7 +877,7 @@ void Render_opengl::draw_line(Element_pos x1, Element_pos y1, Element_pos x2, El
glEnd();
}
void Render_opengl::draw_circle(Element_pos x, Element_pos y, Element_pos z, Element_pos r){
void Render_opengl::draw_circle(Element_pos /*x*/, Element_pos /*y*/, Element_pos /*z*/, Element_pos /*r*/){
/* Circle_ buf;
const Element_pos offset_x = -_default_entity_x_translate;
......@@ -943,7 +943,7 @@ void Render_opengl::start_draw_arrows(){
_draw_arrow = true;
}
void Render_opengl::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height){
void Render_opengl::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height, const Element_col red, const Element_col green, const Element_col blue){
Arrow_ buf;
const Element_pos offset_x = -_default_entity_x_translate;
......@@ -953,6 +953,9 @@ void Render_opengl::draw_arrow(const Element_pos start_time, const Element_pos e
buf.end_time = end_time + offset_x;
buf.start_height = start_height + offset_y;
buf.end_height = end_height + offset_y;
buf.red = red;
buf.green = green;
buf.blue = blue;
_arrows.push_back(buf);
}
......@@ -1030,7 +1033,7 @@ void Render_opengl::draw_stored_arrows(){
Element_pos start_time, end_time, start_height, end_height;
Element_pos scaled_start_time, scaled_end_time, scaled_start_height, scaled_end_height;
set_color(1, 1, 1);
const unsigned int arrow_size = _arrows.size();
for (unsigned int i=0 ; i<arrow_size ; i++){
......@@ -1039,6 +1042,8 @@ void Render_opengl::draw_stored_arrows(){
end_time = _arrows[i].end_time;// + _x_state_scale*_x_state_translate;
start_height = _arrows[i].start_height;
end_height = _arrows[i].end_height;
set_color(_arrows[i].red, _arrows[i].green, _arrows[i].blue);
scaled_start_time = start_time * _x_state_scale;
scaled_end_time = end_time * _x_state_scale;
......
......@@ -66,6 +66,7 @@ struct Arrow_{
* \brief Coordinates.
*/
Element_pos start_time, end_time, start_height, end_height;
Element_col red, green, blue;
};
/*!
......@@ -313,7 +314,7 @@ public:
*
* This function stores all the information of the arrow to display it each time the render area need to be updated.
*/
void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height);
void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height,const Element_col red, const Element_col green, const Element_col blue);
/*!
* \brief Closes the arrow display list.
......
......@@ -132,7 +132,7 @@ void Render_svg::draw_quad(Element_pos x, Element_pos y, Element_pos , Element_p
// std::cout << __FILE__ << " " << __LINE__ << " - " << x << " " << << std::endl;
_buffer.str("");
_buffer << "<rect "
_buffer << "<rect"
<< " x=\"" << render_to_screen_x(x) << "\""
<< " y=\"" << render_to_screen_y(y) << "\""
<< " width=\"" << render_to_screen_x(w) << "\""
......@@ -152,7 +152,7 @@ void Render_svg::draw_triangle(Element_pos x, Element_pos y,
<< render_to_screen_x(x-1.2) << "," << render_to_screen_y(y-0.4) << ","
<< render_to_screen_x(x-1.2) << "," << render_to_screen_y(y+0.4) << "\""
<< " transform = \"rotate("<< r << " " << render_to_screen_x(x) << " " << render_to_screen_y(y) << " )\""
<< " style=\"fill:yellow\""
<< " fill=\"rgb(" << floor(_red*256) << "," << floor(_green*256) << "," << floor(_blue*256) << ")\""/* TODO: choice better scale than '*256' */
<< "/>\n";
_output_file.write(_buffer.str().c_str(), _buffer.str().size());
......@@ -160,12 +160,12 @@ void Render_svg::draw_triangle(Element_pos x, Element_pos y,
void Render_svg::draw_line(Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2, Element_pos ){
_buffer.str("");
_buffer << "<line "
_buffer << "<line"
<< " x1=\"" << render_to_screen_x(x1) << "\""
<< " y1=\"" << render_to_screen_y(y1) << "\""
<< " x2=\"" << render_to_screen_x(x2) << "\""
<< " y2=\"" << render_to_screen_y(y2) << "\""
<< " style=\"stroke:yellow\""
<< " stroke=\"rgb(" << floor(_red*256) << "," << floor(_green*256) << "," << floor(_blue*256) << ")\""/* TODO: choice better scale than '*256' */
<< "/>\n";
_output_file.write(_buffer.str().c_str(), _buffer.str().size());
......@@ -173,10 +173,10 @@ void Render_svg::draw_line(Element_pos x1, Element_pos y1, Element_pos x2, Eleme
void Render_svg::draw_circle(Element_pos x, Element_pos y, Element_pos , Element_pos r){
_buffer.str("");
_buffer << "<circle "
<< "cx=\"" << render_to_screen_x(x) << "\""
<< "cy=\"" << render_to_screen_x(y) << "\""
<< "r=\"" << max(render_to_screen_x(r), render_to_screen_y(r)) << "\""
_buffer << "<circle"
<< " cx=\"" << render_to_screen_x(x) << "\""
<< " cy=\"" << render_to_screen_x(y) << "\""
<< " r=\"" << max(render_to_screen_x(r), render_to_screen_y(r)) << "\""
<< " style=\"fill:yellow\""
<< "/>\n";
......@@ -222,7 +222,7 @@ void Render_svg::end_draw_states(){
void Render_svg::start_draw_arrows(){
}
void Render_svg::draw_arrow(const Element_pos , const Element_pos , const Element_pos , const Element_pos ){
void Render_svg::draw_arrow(const Element_pos , const Element_pos , const Element_pos , const Element_pos, const Element_col, const Element_col, const Element_col){
}
void Render_svg::end_draw_arrows(){
......
......@@ -160,7 +160,7 @@ public:
*
* This function stores all the information of the arrow to display it each time the render area need to be updated.
*/
void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height);
void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height, const Element_col r, const Element_col g, const Element_col b);
/*!
* \brief Closes the arrow display list.
......
......@@ -358,8 +358,12 @@ public:
Variable *var;
const std::list<std::pair<Date, Double> > *variable_values;
int position;
const Color *color;
std::map<std::string, Value *>::const_iterator field;
Element_pos lvl_zoom;
color = NULL;
if(zoom>=0)
lvl_zoom = zoom;
else
......@@ -408,8 +412,19 @@ public:
link = *it;
if(link_is_in_set(link,set_container,interval)){
draw_link(draw_object, link->get_start_time().get_value(), link->get_end_time().get_value(),
_container_positions[link->get_source()], _container_positions[link->get_destination()]);
// Search the color
if (link->get_value() &&
!link->get_value()->get_extra_fields()->empty() &&
((field = link->get_value()->get_extra_fields()->find(std::string("Color"))) != link->get_value()->get_extra_fields()->end()))
/* Call the object link drawing function with the link color */
color = (const Color *)(*field).second;
else
color = NULL;/* NULL = no color */
draw_link(draw_object, link->get_start_time().get_value(), link->get_end_time().get_value(),
_container_positions[link->get_source()], _container_positions[link->get_destination()],
color);
}
}/* end for */
}//end for
......@@ -486,12 +501,17 @@ public:
* \param endtime Time of the end of the link
* \param start Line of the start of the link
* \param end Line of the end of the link
* \param color The link color
*/
template<class T>
inline void draw_link(T *draw_object, double starttime, double endtime, double start, double end) {
inline void draw_link(T *draw_object, double starttime, double endtime, double start, double end, const Color* color) {
Element_pos y1 = (start+0.5)*(_container_height+_container_v_space);
Element_pos y2 = (end+0.5)*(_container_height+_container_v_space);
draw_object->draw_arrow(starttime, endtime, y1, y2);
if (color != NULL)
draw_object->draw_arrow(starttime, endtime, y1, y2, color->get_red(), color->get_green(), color->get_blue());
else/* Draw white link */
draw_object->draw_arrow(starttime, endtime, y1, y2, 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