diff --git a/src/core/Core.cpp b/src/core/Core.cpp index 47b8c071917501a384670f442fea73e6cd2d79b9..58fa6a70a19025887ecf7fd5c8317294dae35416 100644 --- a/src/core/Core.cpp +++ b/src/core/Core.cpp @@ -1315,3 +1315,7 @@ void Core::change_entity_color(std::string entity, Element_col r, Element_col g, std::cout << "core" << std::endl; _render_opengl->change_color(entity, r, g, b); } + +void Core::reload_states(){ + _render_opengl->reload_states(); +} diff --git a/src/core/Core.hpp b/src/core/Core.hpp index cacc42685d0fac240b7b5d52588c068624bb28b8..179ee59eef96567febd35b70fd3cbc1b8ac26711 100644 --- a/src/core/Core.hpp +++ b/src/core/Core.hpp @@ -509,6 +509,10 @@ public: */ 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 signals: diff --git a/src/interface/Settings_window.cpp b/src/interface/Settings_window.cpp index 83dca06aa43563ae9f5c1800e2f1c17963f36816..ffcf1597e19bcca68085de47fbaa97ce2ee3072f 100644 --- a/src/interface/Settings_window.cpp +++ b/src/interface/Settings_window.cpp @@ -427,6 +427,7 @@ void Settings_window::on_reload_states_btn_clicked(){ add_table_line(states_table, SLOT(state_color_changed(const QColor &)), row, (*it).first.c_str(), (*it).second, true); } + _c->reload_states(); } diff --git a/src/render/GanttDiagram.hpp b/src/render/GanttDiagram.hpp index 503601aac0c911cf13a8c28961e42958c5b2456f..ce7f791b0f246a36dcbddece438768f161f6ebd6 100644 --- a/src/render/GanttDiagram.hpp +++ b/src/render/GanttDiagram.hpp @@ -267,7 +267,7 @@ public: * \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); diff --git a/src/render/Render.hpp b/src/render/Render.hpp index 0ea7d0f66636ed41db660a27e211c40d4a8d6fcd..c6076ae767037bf47a47b2022fc441db2b01e8b5 100644 --- a/src/render/Render.hpp +++ b/src/render/Render.hpp @@ -76,7 +76,7 @@ public: */ 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. diff --git a/src/render/Render_alternate.cpp b/src/render/Render_alternate.cpp index 887fbe2a61772a4cda0211e2af8bab1899204233..82ca09f8c7dc24a0ed4000d1cdd105bee07e0171 100644 --- a/src/render/Render_alternate.cpp +++ b/src/render/Render_alternate.cpp @@ -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::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1)); mvp = _projection * _modelview; - std::map<const EntityValue*, Vbo*>::iterator it_state; + std::map<EntityValue*, Vbo*>::iterator it_state; it_state = _states.begin(); while(it_state!=_states.end()){ Shader *s = _states_shaders[it_state->first]; @@ -751,15 +751,15 @@ void Render_alternate::start_draw_states(){ _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){ Shader *s = new Shader(_glsl, _r, _g, _b); s->charger(); //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); Vbo *v = new Vbo(GL_QUADS); - std::pair<const EntityValue*, Vbo*> p2(value, v); + std::pair<EntityValue*, Vbo*> p2(value, v); _states.insert(p2); } _current = _states[value]; @@ -769,7 +769,7 @@ void Render_alternate::draw_state(const Element_pos x, const Element_pos y, cons void Render_alternate::end_draw_states(){ _draw_states = false; - std::map<const EntityValue*, Vbo*>::iterator it; + std::map<EntityValue*, Vbo*>::iterator it; it = _states.begin(); while(it!=_states.end()){ it->second->config(_glsl); @@ -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){ std::cout << "changement shader" << std::endl; - std::map<const EntityValue*, Shader*>::iterator it; + std::map<EntityValue*, Shader*>::iterator it; it = _states_shaders.begin(); while(it != _states_shaders.end()){ std::cout << "salut" << std::endl; @@ -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 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; Shader* s = it->second; delete s; @@ -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++; + } +} diff --git a/src/render/Render_alternate.hpp b/src/render/Render_alternate.hpp index d13baf8e64e2f605f27554f32a07bef2cf9bb3f2..aaab4842623c2b5a69fbeb1d5affa7991e00a70f 100644 --- a/src/render/Render_alternate.hpp +++ b/src/render/Render_alternate.hpp @@ -123,8 +123,8 @@ private: Vbo _ruler; Vbo _wait; Vbo *_current; - std::map<const EntityValue*, Vbo*> _states; - std::map<const EntityValue*, Shader*> _states_shaders; + std::map<EntityValue*, Vbo*> _states; + std::map<EntityValue*, Shader*> _states_shaders; GLuint _textureID; /*! * \brief Offset of the vertical helper line @@ -259,7 +259,7 @@ void start_draw_states(); * \param g the green 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. @@ -554,6 +554,11 @@ public slots: 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(); + }; diff --git a/src/render/Render_opengl.cpp b/src/render/Render_opengl.cpp index 08799762e2914674321135cd03f2a5c6c14d8931..36ca8d0b6bdcb02a434d5509466bc26ecf1b275c 100644 --- a/src/render/Render_opengl.cpp +++ b/src/render/Render_opengl.cpp @@ -872,7 +872,7 @@ void Render_opengl::start_draw_states(){ 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); } diff --git a/src/render/Render_opengl.hpp b/src/render/Render_opengl.hpp index c694bab6b855f65ba0763c982a0c2274b24b9ee9..ceac76f9153e04d3ef4833851594cf5743d07f60 100644 --- a/src/render/Render_opengl.hpp +++ b/src/render/Render_opengl.hpp @@ -379,7 +379,7 @@ public: * \param g the green 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. diff --git a/src/render/Render_svg.cpp b/src/render/Render_svg.cpp index c1e498cba94c4a209d1a5dd5a04ceed414cd0454..43d482512224d3c41fc15ac6276783cb99c27899 100644 --- a/src/render/Render_svg.cpp +++ b/src/render/Render_svg.cpp @@ -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(){ diff --git a/src/render/Render_svg.hpp b/src/render/Render_svg.hpp index fcad47d9e411fa1895dc48da6a749924d109a7dc..73eabe625ee70681f87926d8eee47102c57bdc72 100644 --- a/src/render/Render_svg.hpp +++ b/src/render/Render_svg.hpp @@ -136,7 +136,7 @@ public: * \param g the green 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. diff --git a/src/trace/DrawTree.hpp b/src/trace/DrawTree.hpp index 9945575858f6a9ae24a540233ac9b900d99f4a57..193209a50a971236c8313e52a5caaa45ef8507f2 100644 --- a/src/trace/DrawTree.hpp +++ b/src/trace/DrawTree.hpp @@ -119,7 +119,7 @@ public: * \param g Green 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; _draw_object->draw_state(starttime, endtime, y, _state_height, r, g, b, value); } @@ -239,7 +239,7 @@ struct DrawNode<D, StateChange> { node->get_element()->get_left_state()){ std::map<std::string, Value *>::const_iterator field; 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; extra_fields = state->get_value()->get_extra_fields(); @@ -265,17 +265,18 @@ struct DrawNode<D, StateChange> { extra_fields!=NULL && !extra_fields->empty() && ((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; }else{ 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(), color->get_red(), color->get_green(), color->get_blue(), value); - } + //} diff --git a/src/trace/EntityValue.cpp b/src/trace/EntityValue.cpp index f28105705ff48b29082564c5468a8cf88299479b..bd369e90bbff3b21c4ecd4eb6d09d3184eae0378 100644 --- a/src/trace/EntityValue.cpp +++ b/src/trace/EntityValue.cpp @@ -50,10 +50,12 @@ #include "trace/ContainerType.hpp" #include "trace/EntityType.hpp" #include "trace/EntityValue.hpp" +#include "common/Session.hpp" +#include "common/Palette.hpp" /* -- */ 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) 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 _usedcolor = _filecolor; switch (type->get_class()) { 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_Event: case _EntityClass_Variable: @@ -98,6 +109,22 @@ const map<string, Value *> *EntityValue::get_extra_fields() const { 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(){ _type = NULL; @@ -107,7 +134,8 @@ EntityValue::~EntityValue(){ delete (*it).second; } - if (_usedcolor != _filecolor) + /*if (_usedcolor != _filecolor && _usedcolor!=NULL) delete _usedcolor; - delete _filecolor; + if(_filecolor!=NULL) + delete _filecolor;*/ } diff --git a/src/trace/EntityValue.hpp b/src/trace/EntityValue.hpp index 5fdd6a402c1312b9146118227264ff5ff221248e..203ddf26a37ff5f5437d01aec200bd9dc80aa61d 100644 --- a/src/trace/EntityValue.hpp +++ b/src/trace/EntityValue.hpp @@ -61,6 +61,7 @@ private: Color *_filecolor; Color *_usedcolor; + bool _display; public: /*! @@ -90,6 +91,12 @@ public: */ 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(); }; diff --git a/src/trace/State.cpp b/src/trace/State.cpp index 37f8c369116da71d1bc5add78d4fa8541dfacbaa..f722e59b5a674f21b9bbe3f84a6adcd87c07c8c7 100644 --- a/src/trace/State.cpp +++ b/src/trace/State.cpp @@ -77,6 +77,10 @@ const StateType *State::get_type() const { return _type; } -const EntityValue *State::get_value() const { +/*const EntityValue *State::get_value() const { + return _value; + }*/ + +EntityValue *State::get_value() const { return _value; } diff --git a/src/trace/State.hpp b/src/trace/State.hpp index 8d1790eefdcbe238734ce93f0bc88f89dd23e9a1..ed37c55248d2bd8324756b29cb3cbf4558860c9f 100644 --- a/src/trace/State.hpp +++ b/src/trace/State.hpp @@ -91,7 +91,9 @@ public: * \brief Get the value of the state * \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)