Commit 48fd4526 authored by Thibault Soucarre's avatar Thibault Soucarre

Settings for states corrected

parent d2b4ff74
...@@ -1315,3 +1315,7 @@ void Core::change_entity_color(std::string entity, Element_col r, Element_col g, ...@@ -1315,3 +1315,7 @@ void Core::change_entity_color(std::string entity, Element_col r, Element_col g,
std::cout << "core" << std::endl; std::cout << "core" << std::endl;
_render_opengl->change_color(entity, r, g, b); _render_opengl->change_color(entity, r, g, b);
} }
void Core::reload_states(){
_render_opengl->reload_states();
}
...@@ -509,6 +509,10 @@ public: ...@@ -509,6 +509,10 @@ public:
*/ */
void change_entity_color(std::string entity, Element_col r, Element_col g, Element_col b); void change_entity_color(std::string entity, Element_col r, Element_col g, Element_col b);
/*!
* \brief reload state color from trace file
*/
void reload_states();
//Qt signals fo the Parsing Thread //Qt signals fo the Parsing Thread
signals: signals:
......
...@@ -427,6 +427,7 @@ void Settings_window::on_reload_states_btn_clicked(){ ...@@ -427,6 +427,7 @@ void Settings_window::on_reload_states_btn_clicked(){
add_table_line(states_table, SLOT(state_color_changed(const QColor &)), add_table_line(states_table, SLOT(state_color_changed(const QColor &)),
row, (*it).first.c_str(), (*it).second, true); row, (*it).first.c_str(), (*it).second, true);
} }
_c->reload_states();
} }
......
...@@ -267,7 +267,7 @@ public: ...@@ -267,7 +267,7 @@ public:
* \param b the blue 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, const EntityValue * 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) {
drawing_instance->set_color(r, g, b); drawing_instance->set_color(r, g, b);
......
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
*/ */
virtual void start_draw_states() = 0; virtual void start_draw_states() = 0;
virtual void draw_state(const Element_pos , const Element_pos , const Element_pos , const Element_pos , const Element_pos , const EntityValue* type) = 0; virtual void draw_state(const Element_pos , const Element_pos , const Element_pos , const Element_pos , const Element_pos , EntityValue* type) = 0;
/*! /*!
* \brief Called when all state draws are finished. * \brief Called when all state draws are finished.
......
...@@ -226,7 +226,7 @@ void Render_alternate::paintGL(){ ...@@ -226,7 +226,7 @@ void Render_alternate::paintGL(){
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, _z_state)); _modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, _z_state));
_modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1)); _modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1));
mvp = _projection * _modelview; mvp = _projection * _modelview;
std::map<const EntityValue*, Vbo*>::iterator it_state; std::map<EntityValue*, Vbo*>::iterator it_state;
it_state = _states.begin(); it_state = _states.begin();
while(it_state!=_states.end()){ while(it_state!=_states.end()){
Shader *s = _states_shaders[it_state->first]; Shader *s = _states_shaders[it_state->first];
...@@ -751,15 +751,15 @@ void Render_alternate::start_draw_states(){ ...@@ -751,15 +751,15 @@ void Render_alternate::start_draw_states(){
_draw_states = true; _draw_states = true;
} }
void Render_alternate::draw_state(const Element_pos x, const Element_pos y, const Element_pos z, const Element_pos w, const Element_pos h, const EntityValue* value){ void Render_alternate::draw_state(const Element_pos x, const Element_pos y, const Element_pos z, const Element_pos w, const Element_pos h, EntityValue* value){
if(_states.count(value)==0){ if(_states.count(value)==0){
Shader *s = new Shader(_glsl, _r, _g, _b); Shader *s = new Shader(_glsl, _r, _g, _b);
s->charger(); s->charger();
//assert(value); // TODO: check why busy state exists and uncomment this assert //assert(value); // TODO: check why busy state exists and uncomment this assert
std::pair<const EntityValue*, Shader*> p(value, s); std::pair<EntityValue*, Shader*> p(value, s);
_states_shaders.insert(p); _states_shaders.insert(p);
Vbo *v = new Vbo(GL_QUADS); Vbo *v = new Vbo(GL_QUADS);
std::pair<const EntityValue*, Vbo*> p2(value, v); std::pair<EntityValue*, Vbo*> p2(value, v);
_states.insert(p2); _states.insert(p2);
} }
_current = _states[value]; _current = _states[value];
...@@ -769,7 +769,7 @@ void Render_alternate::draw_state(const Element_pos x, const Element_pos y, cons ...@@ -769,7 +769,7 @@ void Render_alternate::draw_state(const Element_pos x, const Element_pos y, cons
void Render_alternate::end_draw_states(){ void Render_alternate::end_draw_states(){
_draw_states = false; _draw_states = false;
std::map<const EntityValue*, Vbo*>::iterator it; std::map<EntityValue*, Vbo*>::iterator it;
it = _states.begin(); it = _states.begin();
while(it!=_states.end()){ while(it!=_states.end()){
it->second->config(_glsl); it->second->config(_glsl);
...@@ -957,7 +957,7 @@ void Render_alternate::clear_text (){ ...@@ -957,7 +957,7 @@ void Render_alternate::clear_text (){
void Render_alternate::change_color(std::string entity, Element_col r, Element_col g, Element_col b){ void Render_alternate::change_color(std::string entity, Element_col r, Element_col g, Element_col b){
std::cout << "changement shader" << std::endl; std::cout << "changement shader" << std::endl;
std::map<const EntityValue*, Shader*>::iterator it; std::map<EntityValue*, Shader*>::iterator it;
it = _states_shaders.begin(); it = _states_shaders.begin();
while(it != _states_shaders.end()){ while(it != _states_shaders.end()){
std::cout << "salut" << std::endl; std::cout << "salut" << std::endl;
...@@ -965,6 +965,8 @@ void Render_alternate::change_color(std::string entity, Element_col r, Element_c ...@@ -965,6 +965,8 @@ void Render_alternate::change_color(std::string entity, Element_col r, Element_c
//assert(it->first); // TODO: check why busy state exists and uncomment this assert //assert(it->first); // TODO: check why busy state exists and uncomment this assert
if(it->first && (it->first->get_name() == entity)){ if(it->first && (it->first->get_name() == entity)){
Color *c = new Color(r, g, b);
it->first->set_used_color(c);
std::cout << "rentré dans le if" << std::endl; std::cout << "rentré dans le if" << std::endl;
Shader* s = it->second; Shader* s = it->second;
delete s; delete s;
...@@ -977,3 +979,17 @@ void Render_alternate::change_color(std::string entity, Element_col r, Element_c ...@@ -977,3 +979,17 @@ void Render_alternate::change_color(std::string entity, Element_col r, Element_c
} }
} }
void Render_alternate::reload_states(){
std::map<EntityValue*, Shader*>::iterator it;
it = _states_shaders.begin();
while(it != _states_shaders.end()){
it->first->reload_file_color();
Shader* s = it->second;
delete s;
s = new Shader(_glsl, it->first->get_used_color()->get_red(),
it->first->get_used_color()->get_green(),
it->first->get_used_color()->get_blue());
s->charger();
it++;
}
}
...@@ -123,8 +123,8 @@ private: ...@@ -123,8 +123,8 @@ private:
Vbo _ruler; Vbo _ruler;
Vbo _wait; Vbo _wait;
Vbo *_current; Vbo *_current;
std::map<const EntityValue*, Vbo*> _states; std::map<EntityValue*, Vbo*> _states;
std::map<const EntityValue*, Shader*> _states_shaders; std::map<EntityValue*, Shader*> _states_shaders;
GLuint _textureID; GLuint _textureID;
/*! /*!
* \brief Offset of the vertical helper line * \brief Offset of the vertical helper line
...@@ -259,7 +259,7 @@ void start_draw_states(); ...@@ -259,7 +259,7 @@ void start_draw_states();
* \param g the green color rate of the state. * \param g the green color rate of the state.
* \param b the blue color rate of the state. * \param b the blue color rate of the state.
*/ */
void draw_state(const Element_pos start , const Element_pos end, const Element_pos base, const Element_pos height, const Element_pos r, const EntityValue* type); void draw_state(const Element_pos start , const Element_pos end, const Element_pos base, const Element_pos height, const Element_pos r, EntityValue* type);
/*! /*!
* \brief Closes the state display list. * \brief Closes the state display list.
...@@ -554,6 +554,11 @@ public slots: ...@@ -554,6 +554,11 @@ public slots:
void change_color(std::string entity, Element_col r, Element_col g, Element_col b); void change_color(std::string entity, Element_col r, Element_col g, Element_col b);
/*!
* \brief reload state color from trace file
*/
void reload_states();
}; };
......
...@@ -872,7 +872,7 @@ void Render_opengl::start_draw_states(){ ...@@ -872,7 +872,7 @@ void Render_opengl::start_draw_states(){
glNewList(_list_states, GL_COMPILE);/* open the list */ glNewList(_list_states, GL_COMPILE);/* open the list */
} }
void Render_opengl::draw_state(const Element_pos x, const Element_pos y, const Element_pos z, const Element_pos w, const Element_pos h, const EntityValue* value){ void Render_opengl::draw_state(const Element_pos x, const Element_pos y, const Element_pos z, const Element_pos w, const Element_pos h, EntityValue* value){
draw_quad(x, y, z, w, h); draw_quad(x, y, z, w, h);
} }
......
...@@ -379,7 +379,7 @@ public: ...@@ -379,7 +379,7 @@ public:
* \param g the green color rate of the state. * \param g the green color rate of the state.
* \param b the blue color rate of the state. * \param b the blue color rate of the state.
*/ */
void draw_state(const Element_pos, const Element_pos, const Element_pos, const Element_pos, const Element_col, const EntityValue* ); void draw_state(const Element_pos, const Element_pos, const Element_pos, const Element_pos, const Element_col, EntityValue* );
/*! /*!
* \brief Closes the state display list. * \brief Closes the state display list.
......
...@@ -221,7 +221,7 @@ void Render_svg::start_draw_states(){ ...@@ -221,7 +221,7 @@ void Render_svg::start_draw_states(){
} }
void Render_svg::draw_state(const Element_pos, const Element_pos, const Element_pos, const Element_pos, const Element_col, const EntityValue* ){ void Render_svg::draw_state(const Element_pos, const Element_pos, const Element_pos, const Element_pos, const Element_col, EntityValue* ){
} }
void Render_svg::end_draw_states(){ void Render_svg::end_draw_states(){
......
...@@ -136,7 +136,7 @@ public: ...@@ -136,7 +136,7 @@ public:
* \param g the green color rate of the state. * \param g the green color rate of the state.
* \param b the blue color rate of the state. * \param b the blue color rate of the state.
*/ */
void draw_state(const Element_pos, const Element_pos, const Element_pos, const Element_pos, const Element_col, const EntityValue* ); void draw_state(const Element_pos, const Element_pos, const Element_pos, const Element_pos, const Element_col, EntityValue* );
/*! /*!
* \brief Closes the state display list. * \brief Closes the state display list.
......
...@@ -119,7 +119,7 @@ public: ...@@ -119,7 +119,7 @@ public:
* \param g Green value of the state color * \param g Green value of the state color
* \param b Blue value of the state color * \param b Blue value of the state color
*/ */
inline void draw_state(double starttime, double endtime, double r, double g, double b, const EntityValue * value) { inline void draw_state(double starttime, double endtime, double r, double g, double b, EntityValue * value) {
Element_pos y = _position + _container_v_space/2; Element_pos y = _position + _container_v_space/2;
_draw_object->draw_state(starttime, endtime, y, _state_height, r, g, b, value); _draw_object->draw_state(starttime, endtime, y, _state_height, r, g, b, value);
} }
...@@ -239,7 +239,7 @@ struct DrawNode<D, StateChange> { ...@@ -239,7 +239,7 @@ struct DrawNode<D, StateChange> {
node->get_element()->get_left_state()){ node->get_element()->get_left_state()){
std::map<std::string, Value *>::const_iterator field; std::map<std::string, Value *>::const_iterator field;
const State *state = node->get_element()->get_left_state(); const State *state = node->get_element()->get_left_state();
const std::map<std::string, Value *> *extra_fields; /*const std::map<std::string, Value *> *extra_fields;
const Color *color=NULL; const Color *color=NULL;
extra_fields = state->get_value()->get_extra_fields(); extra_fields = state->get_value()->get_extra_fields();
...@@ -265,17 +265,18 @@ struct DrawNode<D, StateChange> { ...@@ -265,17 +265,18 @@ struct DrawNode<D, StateChange> {
extra_fields!=NULL && extra_fields!=NULL &&
!extra_fields->empty() && !extra_fields->empty() &&
((field = extra_fields->find(std::string("Color"))) != extra_fields->end())) { ((field = extra_fields->find(std::string("Color"))) != extra_fields->end())) {
/* Call the object state drawing function with the state color */ // Call the object state drawing function with the state color
color = (const Color *)(*field).second; color = (const Color *)(*field).second;
}else{ }else{
color=new Color(0.7, 0.7, 0.75); color=new Color(0.7, 0.7, 0.75);
} }
} }*/
const EntityValue * value = state->get_value(); EntityValue * value = state->get_value();
const Color * color = value->get_used_color();
draw->draw_state(interval->_left.get_value(), state->get_end_time().get_value(), draw->draw_state(interval->_left.get_value(), state->get_end_time().get_value(),
color->get_red(), color->get_green(), color->get_blue(), value); color->get_red(), color->get_green(), color->get_blue(), value);
} //}
......
...@@ -50,10 +50,12 @@ ...@@ -50,10 +50,12 @@
#include "trace/ContainerType.hpp" #include "trace/ContainerType.hpp"
#include "trace/EntityType.hpp" #include "trace/EntityType.hpp"
#include "trace/EntityValue.hpp" #include "trace/EntityValue.hpp"
#include "common/Session.hpp"
#include "common/Palette.hpp"
/* -- */ /* -- */
using namespace std; using namespace std;
EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Value *> opt): _name(name), _type(type), _opt(opt) { EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Value *> opt): _name(name), _type(type), _opt(opt), _display(true){
// Search opt field for color to set the default (random if not provided within the trace file) // Search opt field for color to set the default (random if not provided within the trace file)
map<std::string, Value *>::iterator it = opt.find(string("Color")); map<std::string, Value *>::iterator it = opt.find(string("Color"));
...@@ -71,6 +73,15 @@ EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Va ...@@ -71,6 +73,15 @@ EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Va
_usedcolor = _filecolor; _usedcolor = _filecolor;
switch (type->get_class()) { switch (type->get_class()) {
case _EntityClass_State: case _EntityClass_State:
if(Session::get_use_palette("palette")){
Palette *sp = Session::get_palette("palette", Session::get_current_palette("palette"));
Color* color = sp->get_color(type->get_name().to_string());
if(!color)
_display=false;
else
_usedcolor = color;
}
break;
case _EntityClass_Link: case _EntityClass_Link:
case _EntityClass_Event: case _EntityClass_Event:
case _EntityClass_Variable: case _EntityClass_Variable:
...@@ -98,6 +109,22 @@ const map<string, Value *> *EntityValue::get_extra_fields() const { ...@@ -98,6 +109,22 @@ const map<string, Value *> *EntityValue::get_extra_fields() const {
return &_opt; return &_opt;
} }
const Color* EntityValue::get_used_color() const{
return _usedcolor;
}
void EntityValue::set_used_color(Color *c){
if(_usedcolor!=_filecolor)
delete _usedcolor;
_usedcolor = c;
}
void EntityValue::reload_file_color(){
if(_usedcolor!=_filecolor)
delete _usedcolor;
_usedcolor = _filecolor;
}
EntityValue::~EntityValue(){ EntityValue::~EntityValue(){
_type = NULL; _type = NULL;
...@@ -107,7 +134,8 @@ EntityValue::~EntityValue(){ ...@@ -107,7 +134,8 @@ EntityValue::~EntityValue(){
delete (*it).second; delete (*it).second;
} }
if (_usedcolor != _filecolor) /*if (_usedcolor != _filecolor && _usedcolor!=NULL)
delete _usedcolor; delete _usedcolor;
delete _filecolor; if(_filecolor!=NULL)
delete _filecolor;*/
} }
...@@ -61,6 +61,7 @@ private: ...@@ -61,6 +61,7 @@ private:
Color *_filecolor; Color *_filecolor;
Color *_usedcolor; Color *_usedcolor;
bool _display;
public: public:
/*! /*!
...@@ -90,6 +91,12 @@ public: ...@@ -90,6 +91,12 @@ public:
*/ */
const std::map<std::string, Value *> *get_extra_fields() const; const std::map<std::string, Value *> *get_extra_fields() const;
const Color * get_used_color() const;
void set_used_color(Color *c);
void reload_file_color();
virtual ~EntityValue(); virtual ~EntityValue();
}; };
......
...@@ -77,6 +77,10 @@ const StateType *State::get_type() const { ...@@ -77,6 +77,10 @@ const StateType *State::get_type() const {
return _type; return _type;
} }
const EntityValue *State::get_value() const { /*const EntityValue *State::get_value() const {
return _value;
}*/
EntityValue *State::get_value() const {
return _value; return _value;
} }
...@@ -91,7 +91,9 @@ public: ...@@ -91,7 +91,9 @@ public:
* \brief Get the value of the state * \brief Get the value of the state
* \return Pointer to the Entityvalue or NULL if it has no value * \return Pointer to the Entityvalue or NULL if it has no value
*/ */
const EntityValue *get_value() const; //const EntityValue *get_value() const;
EntityValue *get_value() const;
/*! /*!
* \fn set_left_date(Date) * \fn set_left_date(Date)
......
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