Commit e50d81d7 authored by Mathieu Faverge's avatar Mathieu Faverge

Indent and cleanup Gantt Diagram generation

parent e04c85e0
......@@ -86,7 +86,7 @@ private:
/*!
* This attribute store the instance of a drawing class. (OpenGL or SVG for example)
*/
Render* drawing_instance;
Render *_render;
/*!
* \brief Used to draw counter.
......@@ -94,7 +94,7 @@ private:
bool _start_new_line;
std::vector<Container_> _containers;
std::vector<Container_> _containers;
std::vector<Container_text_> _container_texts;
/*!
......@@ -116,7 +116,7 @@ public:
* \brief The default constructor
*/
GanttDiagram(Render* instance){
drawing_instance = instance;
_render = instance;
}
/*!
......@@ -140,7 +140,7 @@ public:
_containers.clear();
_container_texts.clear();
drawing_instance->start_draw();
_render->start_draw();
std::cout << "Gantt::start_draw" << std::endl;
}
......@@ -157,9 +157,14 @@ public:
* \param w the width of the container
* \param h the height of the container
*/
inline void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h, const std::string &value){
Container_ buf;
inline void draw_container(const Element_pos x,
const Element_pos y,
const Element_pos w,
const Element_pos h,
const std::string &value)
{
Container_text_ buft;
Container_ buf;
buf.x = x;
buf.y = y;
......@@ -168,7 +173,6 @@ public:
_containers.push_back(buf);
Container_text_ buft;
buft.x = x + w/5;
buft.y = y + h/2;
buft.value = value;
......@@ -193,7 +197,6 @@ public:
std::cerr << "x: " << x << " y: " << y << " w: " << w << " h: " << h << " xmax-xmin: " << Info::Container::x_max << " - " << Info::Container::x_min << " ymax-ymin: " << Info::Container::y_max << " - " << Info::Container::y_min << std::endl;
#endif
}
/*!
......@@ -204,58 +207,53 @@ public:
*
* This function stores text in a list. This list will be display each time the render area need to be updated.
*/
inline void draw_container_text(const Element_pos x, const Element_pos y, const std::string value){
/*Container_text_ buf;
buf.x = x;
buf.y = y;
buf.value = value;
_container_texts.push_back(buf);*/
inline void draw_container_text(const Element_pos x, const Element_pos y, const std::string value)
{
return;
}
/*!
* \brief Closes the container display list.
*/
inline void end_draw_containers(){
float j = 0.6f;
inline void end_draw_containers()
{
static float j = 0.6f;
float coeffx = (Info::Render::width /Info::Container::x_max) * _x_scale_container_state;
float coeffy = ((Info::Render::height-_ruler_height)/Info::Container::y_max) * _y_state_scale;
// std::cout << __FILE__ << " ~~ " << __LINE__ << " " << Info::Container::y_max << " " << Info::Container::y_min << std::endl;
/* Before calling start_draw_container(), Info::Container::y_max should have a correct value */
drawing_instance->start_draw_containers();
_render->start_draw_containers();
for (unsigned int i=0 ; i<_containers.size() ; i++){
drawing_instance->set_color(0, 0, j);
drawing_instance->draw_quad(_containers[i].x * (Info::Render::width/Info::Container::x_max)*_x_scale_container_state,
trace_to_render_y(_containers[i].y),// * _y_state_scale*(_render_height-_ruler_height)/Info::Container::y_max) - _y_state_translate + _ruler_y + _ruler_height,
_z_container,
_containers[i].w * (Info::Render::width/Info::Container::x_max)*_x_scale_container_state,
_containers[i].h * _y_state_scale*(Info::Render::height-_ruler_height)/Info::Container::y_max);
_render->set_color(0, 0, j);
_render->draw_quad(_containers[i].x * coeffx,
trace_to_render_y(_containers[i].y),
_z_container,
_containers[i].w * coeffx,
_containers[i].h * coeffy);
}
// std::cout << __FILE__ << " ~ " << __LINE__ << " " << Info::Container::y_max << " " << Info::Container::y_min << std::endl;
for (unsigned int i=0 ; i<_container_texts.size() ; i++){
_container_texts[i].x *= (Info::Render::width/Info::Container::x_max)*_x_scale_container_state;
_container_texts[i].y = trace_to_render_y(_container_texts[i].y);// + _render_height-_ruler_height)*coeff_trace_render_y();
_container_texts[i].x *= coeffx;
_container_texts[i].y = trace_to_render_y(_container_texts[i].y);
drawing_instance->draw_text(_container_texts[i].x, _container_texts[i].y, /*_z_container+1*/_containers[i].w * (Info::Render::width/Info::Container::x_max)*_x_scale_container_state, _container_texts[i].value);
_render->draw_text(_container_texts[i].x,
_container_texts[i].y,
_containers[i].w * coeffx,
_container_texts[i].value);
}
drawing_instance->end_draw_containers();
_render->end_draw_containers();
}
static int bb;
/*!
* \brief Creates and opens the display list for state draws.
*/
inline void start_draw_states(){
drawing_instance->start_draw_states();
inline void start_draw_states()
{
_render->start_draw_states();
}
/*!
* \brief Draw a state of the trace.
* \param start the beginning time of the state.
......@@ -266,36 +264,38 @@ public:
* \param g the green color rate of the state.
* \param b the blue color rate of the state.
*/
inline void draw_state(const Element_pos start, const Element_pos end, const Element_pos base, const Element_pos height, const Element_col r, const Element_col g, const Element_col b, EntityValue * value) {
drawing_instance->set_color(r, g, b);
/*drawing_instance->draw_quad(trace_to_render_x(start - Info::Render::_x_min_visible),
trace_to_render_y(base),
_z_state,
(end-start)*coeff_trace_render_x(),
height*coeff_trace_render_y());*/
drawing_instance->draw_state(trace_to_render_x(start - Info::Render::_x_min_visible),
trace_to_render_y(base),
_z_state,
(end-start)*coeff_trace_render_x(),
height*coeff_trace_render_y(),
value);
inline void draw_state(const Element_pos start,
const Element_pos end,
const Element_pos base,
const Element_pos height,
const Element_col r,
const Element_col g,
const Element_col b,
EntityValue * value)
{
_render->set_color(r, g, b);
_render->draw_state(trace_to_render_x(start - Info::Render::_x_min_visible),
trace_to_render_y(base),
_z_state,
(end-start)*coeff_trace_render_x(),
height *coeff_trace_render_y(),
value);
}
/*!
* \brief Closes the state display list.
*/
inline void end_draw_states(){
drawing_instance->end_draw_states();
inline void end_draw_states()
{
_render->end_draw_states();
}
/*!
* \brief Open the arrow display list.
*/
inline void start_draw_arrows(){
drawing_instance->start_draw_arrows();
inline void start_draw_arrows()
{
_render->start_draw_arrows();
}
/*!
......@@ -307,45 +307,51 @@ 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, const Element_col r, const Element_col g, const Element_col b, EntityValue* value){
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,
EntityValue* value)
{
/* 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);
_render->set_color(r, g, b);
start_time = trace_to_render_x(start_time - Info::Render::_x_min_visible);
end_time = trace_to_render_x(end_time - Info::Render::_x_min_visible);
end_time = trace_to_render_x(end_time - Info::Render::_x_min_visible);
start_height = trace_to_render_y(start_height);
end_height = trace_to_render_y(end_height);
if (start_time != end_time)
angle = atan2((end_height - start_height), (end_time - start_time))*coeff;/* arc tangent */
angle = atan2((end_height - start_height), (end_time - start_time))*coeff;
else
angle = 90;
drawing_instance->draw_triangle(end_time, end_height, triangle_size, angle);
drawing_instance->draw_line(start_time, start_height,
end_time, end_height, _z_arrow);
_render->draw_triangle(end_time, end_height, triangle_size, angle);
_render->draw_line(start_time, start_height, end_time, end_height, _z_arrow);
/* For OpenGL */
drawing_instance->draw_arrow(start_time, end_time, start_height, end_height, r, g, b, value);
drawing_instance->set_color(1, 1, 1);/* init */
_render->draw_arrow(start_time, end_time, start_height, end_height, r, g, b, value);
_render->set_color(1, 1, 1);/* init */
}
/*!
* \brief Closes the arrow display list.
*/
inline void end_draw_arrows(){
drawing_instance->end_draw_arrows();
inline void end_draw_arrows()
{
_render->end_draw_arrows();
}
inline void start_draw_events(){
drawing_instance->start_draw_events();
inline void start_draw_events()
{
_render->start_draw_events();
}
/*!
......@@ -356,46 +362,53 @@ 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, const Element_col r, const Element_col g, const Element_col b, EntityValue* value){
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,
EntityValue* value)
{
/* For SVG */
drawing_instance->set_color(r, g, b);
_render->set_color(r, g, b);
time = trace_to_render_x(time - Info::Render::_x_min_visible);
height = trace_to_render_y(height);
container_height = container_height*coeff_trace_render_y();
/* For OpenGL */
drawing_instance->draw_event(time, height, container_height, value);
_render->draw_event(time, height, container_height, value);
}
inline void end_draw_events(){
drawing_instance->end_draw_events();
inline void end_draw_events()
{
_render->end_draw_events();
}
/*!
* \brief Creates and opens the display list for counter draws.
*/
inline void start_draw_counter(){
drawing_instance->set_color(1.0, 1.0, 1.0);
inline void start_draw_counter()
{
_render->set_color(1.0, 1.0, 1.0);
_counter_last_x=0.0;
_counter_last_y=0.0;
drawing_instance->start_draw_counter();
_render->start_draw_counter();
_start_new_line = true;
}
/*!
* \brief Draw a text with the value of a variable
* \param text text to draw.
* \param y y position of the point.
*
*/
inline void draw_text_value(long int id, double text, double y){
drawing_instance->draw_text_value(id,text,y);
inline void draw_text_value(long int id, double text, double y)
{
_render->draw_text_value(id,text,y);
}
/*!
* \brief Draw a point of the counter.
* \param x x position of the point.
......@@ -403,112 +416,90 @@ public:
*
* Each time counter is increased, this function is called with the coordinates of the new point.
*/
inline void draw_counter(const Element_pos x, const Element_pos y){
inline void draw_counter(const Element_pos x, const Element_pos y)
{
if (_start_new_line){/* Start a new line */
_counter_last_x = x;
_counter_last_y = y;
_start_new_line = false;
}else{/* line is already started */
}
else
{/* line is already started */
if (x <= 0.0){/* convention: the line is over */
// drawing_instance->draw_line( _counter_last_x, _counter_last_y,
// _state_x_max, _counter_last_y, _z_counter);
drawing_instance->draw_line( trace_to_render_x(_counter_last_x - Info::Render::_x_min_visible), trace_to_render_y(_counter_last_y),
trace_to_render_x(Info::Entity::x_max), trace_to_render_y(_counter_last_y), _z_counter);
_render->draw_line( trace_to_render_x(_counter_last_x - Info::Render::_x_min_visible),
trace_to_render_y(_counter_last_y),
trace_to_render_x(Info::Entity::x_max),
trace_to_render_y(_counter_last_y),
_z_counter );
_start_new_line = true;
}else{/* add new points to the line */
}
else
{/* add new points to the line */
/* Each time, the method draw the line from the previous point to
the current point (x, y). This last is stored for the next line drawing. */
// drawing_instance->draw_line( _counter_last_x, _counter_last_y,
// x, _counter_last_y, _z_counter);
// drawing_instance->draw_line( x, _counter_last_y,
// x, y, _z_counter);
drawing_instance->draw_line( trace_to_render_x(_counter_last_x - Info::Render::_x_min_visible), trace_to_render_y(_counter_last_y),
trace_to_render_x(x - Info::Render::_x_min_visible), trace_to_render_y(_counter_last_y), _z_counter);
drawing_instance->draw_line( trace_to_render_x(x - Info::Render::_x_min_visible), trace_to_render_y(_counter_last_y),
trace_to_render_x(x - Info::Render::_x_min_visible), trace_to_render_y(y), _z_counter);
_render->draw_line( trace_to_render_x(_counter_last_x - Info::Render::_x_min_visible),
trace_to_render_y(_counter_last_y),
trace_to_render_x(x - Info::Render::_x_min_visible),
trace_to_render_y(_counter_last_y),
_z_counter );
_render->draw_line( trace_to_render_x(x - Info::Render::_x_min_visible),
trace_to_render_y(_counter_last_y),
trace_to_render_x(x - Info::Render::_x_min_visible),
trace_to_render_y(y),
_z_counter );
_counter_last_x = x;
_counter_last_y = y;
}
}
}
/*!
* \brief Closes the counter display list.
*/
inline void end_draw_counter(){
inline void end_draw_counter()
{
if (!_start_new_line) {/* If a line was previously opened */
/* Draw the last line */
// drawing_instance->draw_line( _counter_last_x, _counter_last_y,
// _state_x_max, _counter_last_y, _z_counter);
drawing_instance->draw_line( trace_to_render_x(_counter_last_x - Info::Render::_x_min_visible), trace_to_render_y(_counter_last_y),
trace_to_render_x(Info::Entity::x_max), trace_to_render_y(_counter_last_y), _z_counter);
_render->draw_line( trace_to_render_x(_counter_last_x - Info::Render::_x_min_visible),
trace_to_render_y(_counter_last_y),
trace_to_render_x(Info::Entity::x_max),
trace_to_render_y(_counter_last_y),
_z_counter );
}
drawing_instance->end_draw_counter();
_render->end_draw_counter();
}
/*!
* \brief Do nothing (it is present for compatibility of the Render class).
*/
inline void end_draw(){
inline void end_draw()
{
std::ostringstream buf_txt;
Element_pos graduation_diff;
//Element_pos coeff_prefix;
const Element_pos offset_x = 0;
const Element_pos offset_y = 0;
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);
/* Now, draw ruler */
/*Rendering is done in paintGL because we need to recalculate graduations each time paintGL is called, not just when launching the program*/
drawing_instance->start_ruler();
_render->start_ruler();
{
//drawing_instance->call_ruler();
//_render->call_ruler();
}
drawing_instance->end_ruler();
_render->end_ruler();
/* clear vectors */
_containers.clear();
_container_texts.clear();
drawing_instance->end_draw();
_render->end_draw();
}
/* void browse_container_tree(Trace* trace, std::list<const Container *> l){
const Container::Vector * root_containers = trace->get_root_containers();
if (root_containers->empty()) {
*Message::get_instance() << QObject::tr("There is no container. The trace can not be drawn.").toStdString() << Message::endw;
return;
}
ListContainer root_containers();
ContainerNode *tmp;
for (Container::VectorIt i = root_containers->begin();
i != root_containers->end();
i++)
{
// Use the fact that if a container is selected, then it implies that all his ancestors are
tmp = new ContainerNode(*i, NULL);
root_containers.add(tmp);
}
// position += browse_container(draw_object, *i, position, 0,container);
}
*/
};
#endif
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