Commit 9491fc46 authored by Thibault Soucarre's avatar Thibault Soucarre

visible available in settings for states

parent 3a39e1c0
...@@ -1316,6 +1316,11 @@ void Core::change_entity_color(std::string entity, Element_col r, Element_col g, ...@@ -1316,6 +1316,11 @@ void Core::change_entity_color(std::string entity, Element_col r, Element_col g,
_render_opengl->change_color(entity, r, g, b); _render_opengl->change_color(entity, r, g, b);
} }
void Core::change_entity_visible(std::string entity, bool visible){
std::cout << "core" << std::endl;
_render_opengl->change_visible(entity, visible);
}
void Core::reload_states(){ void Core::reload_states(){
_render_opengl->reload_states(); _render_opengl->reload_states();
} }
...@@ -509,6 +509,7 @@ public: ...@@ -509,6 +509,7 @@ 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);
void change_entity_visible(std::string entity, bool visible);
/*! /*!
* \brief reload state color from trace file * \brief reload state color from trace file
*/ */
......
...@@ -213,8 +213,34 @@ void Settings_window::color_changed(string name, QTableWidget *table, const QCol ...@@ -213,8 +213,34 @@ void Settings_window::color_changed(string name, QTableWidget *table, const QCol
return; return;
} }
void Settings_window::visible_changed(string name, QTableWidget *table, const bool checked){
_changed = true;
if( !table || !palette_list)
return;
int row = 0;
while(table->cellWidget(row, 2) &&
table->cellWidget(row, 2) != sender()) { // Find the row of the checkBox
row ++;
}
if(!table->cellWidget(row, 2))
return; // epic fail...
std::string palette_name = palette_list->currentText().toStdString();
std::string state_name = table->item(row, 0)->text().toStdString();
Session &S = Session::getSession();
Palette *p = S.get_palette(name, palette_name);////////////////////////////
QColor qc = qobject_cast<QtColorPicker *>(table->cellWidget(row, 1))->currentColor();
Color color(qc.red()/255, qc.green()/255, qc.blue()/255);
S.add_state_to_palette(name, palette_name, state_name, color, checked );
p->add_state(state_name, color, checked );
std::pair<std::string, bool> change(state_name, checked);
_states_visible_changes.insert(change);
return;
}
void Settings_window::add_table_line(QTableWidget *table, void Settings_window::add_table_line(QTableWidget *table,
const char *slot, const char *color_slot,
const char *visible_slot,
int &row, std::string st_name, Color *c, bool checked) { int &row, std::string st_name, Color *c, bool checked) {
/* Name */ /* Name */
QTableWidgetItem *name = new QTableWidgetItem(st_name.c_str()); QTableWidgetItem *name = new QTableWidgetItem(st_name.c_str());
...@@ -231,11 +257,12 @@ void Settings_window::add_table_line(QTableWidget *table, ...@@ -231,11 +257,12 @@ void Settings_window::add_table_line(QTableWidget *table,
} }
color_widget->setColorDialogEnabled(false); color_widget->setColorDialogEnabled(false);
connect(color_widget, SIGNAL(colorChanged(const QColor &)), connect(color_widget, SIGNAL(colorChanged(const QColor &)),
this, slot ); this, color_slot );
/* Visible */ /* Visible */
QCheckBox *cb = new QCheckBox(); QCheckBox *cb = new QCheckBox();
cb->setChecked(checked); cb->setChecked(checked);
connect(cb, SIGNAL(stateChanged(int)), this, visible_slot);
table->insertRow(row); table->insertRow(row);
table->setItem(row, 0, name); table->setItem(row, 0, name);
...@@ -245,7 +272,8 @@ void Settings_window::add_table_line(QTableWidget *table, ...@@ -245,7 +272,8 @@ void Settings_window::add_table_line(QTableWidget *table,
} }
void Settings_window::fill_table( QTableWidget *table, void Settings_window::fill_table( QTableWidget *table,
const char *slot, const char *color_slot,
const char *visible_slot,
const string pname, const string pname,
const string &palette_name ) const string &palette_name )
{ {
...@@ -278,7 +306,7 @@ void Settings_window::fill_table( QTableWidget *table, ...@@ -278,7 +306,7 @@ void Settings_window::fill_table( QTableWidget *table,
for(it = colors_settings.begin(); for(it = colors_settings.begin();
it != colors_settings.end(); ++it) it != colors_settings.end(); ++it)
{ {
add_table_line(table, slot, add_table_line(table, color_slot, visible_slot,
row, it->first, it->second, p->is_visible( it->first )); row, it->first, it->second, p->is_visible( it->first ));
} }
} }
...@@ -287,29 +315,45 @@ void Settings_window::state_color_changed(const QColor &qc) { ...@@ -287,29 +315,45 @@ void Settings_window::state_color_changed(const QColor &qc) {
color_changed("palette", states_table, qc); color_changed("palette", states_table, qc);
} }
void Settings_window::state_visible_changed(int checked){
std::cout << "SLOT" << std::endl;
visible_changed("palette", states_table, checked!=0);
}
void Settings_window::event_types_color_changed(const QColor &qc) { void Settings_window::event_types_color_changed(const QColor &qc) {
color_changed("event_types", event_types_table, qc); color_changed("event_types", event_types_table, qc);
} }
void Settings_window::event_types_visible_changed(int checked){
visible_changed("event_types", event_types_table, checked!=0);
}
void Settings_window::link_types_color_changed(const QColor &qc) { void Settings_window::link_types_color_changed(const QColor &qc) {
color_changed("link_types", link_types_table, qc); color_changed("link_types", link_types_table, qc);
} }
void Settings_window::link_types_visible_changed(int checked) {
visible_changed("link_types", link_types_table, checked!=0);
}
void Settings_window::fill_table_states( const string &palette_name ) { void Settings_window::fill_table_states( const string &palette_name ) {
fill_table( states_table, fill_table( states_table,
SLOT(state_color_changed(const QColor &)), SLOT(state_color_changed(const QColor &)),
SLOT(state_visible_changed(int)),
"palette", palette_name ); "palette", palette_name );
} }
void Settings_window::fill_table_events( const string &palette_name ) { void Settings_window::fill_table_events( const string &palette_name ) {
fill_table( event_types_table, fill_table( event_types_table,
SLOT(event_types_color_changed(const QColor &)), SLOT(event_types_color_changed(const QColor &)),
SLOT(event_types_visible_changed(int)),
"event_types", palette_name ); "event_types", palette_name );
} }
void Settings_window::fill_table_links( const string &palette_name ) { void Settings_window::fill_table_links( const string &palette_name ) {
fill_table( link_types_table, fill_table( link_types_table,
SLOT(link_types_color_changed(const QColor &)), SLOT(link_types_color_changed(const QColor &)),
SLOT(links_types_visible_changed(int)),
"link_types", palette_name ); "link_types", palette_name );
} }
...@@ -426,12 +470,13 @@ void Settings_window::on_reload_states_btn_clicked(){ ...@@ -426,12 +470,13 @@ void Settings_window::on_reload_states_btn_clicked(){
for(map<string, Color *>::iterator it = colors.begin() ; for(map<string, Color *>::iterator it = colors.begin() ;
it != colors.end() ; ++ it) { it != colors.end() ; ++ it) {
add_table_line(states_table, SLOT(state_color_changed(const QColor &)), add_table_line(states_table, SLOT(state_color_changed(const QColor &)), SLOT(state_visible_changed(int checked)),
row, (*it).first.c_str(), (*it).second, true); row, (*it).first.c_str(), (*it).second, true);
} }
//_c->reload_states(); //_c->reload_states();
_reload = true; _reload = true;
_states_changes.clear(); _states_changes.clear();
_states_visible_changes.clear();
} }
...@@ -520,7 +565,7 @@ void Settings_window::on_reload_link_types_palette_btn_clicked() { ...@@ -520,7 +565,7 @@ void Settings_window::on_reload_link_types_palette_btn_clicked() {
} }
add_table_line(link_types_table, SLOT(link_types_color_changed(const QColor&)), add_table_line(link_types_table, SLOT(link_types_color_changed(const QColor&)), SLOT(liks_types_visible_changed(int checked)),
row, (*it).first.to_string(), color, true); row, (*it).first.to_string(), color, true);
} }
...@@ -551,7 +596,7 @@ void Settings_window::on_reload_event_types_palette_btn_clicked() { ...@@ -551,7 +596,7 @@ void Settings_window::on_reload_event_types_palette_btn_clicked() {
} }
add_table_line(event_types_table, SLOT(event_types_color_changed(const QColor&)), add_table_line(event_types_table, SLOT(event_types_color_changed(const QColor&)), SLOT(event_types_visible_changed(int checked)),
row, (*it).first.to_string(), color, true); row, (*it).first.to_string(), color, true);
} }
} }
...@@ -680,7 +725,13 @@ void Settings_window::on_apply_clicked() { ...@@ -680,7 +725,13 @@ void Settings_window::on_apply_clicked() {
_c->change_entity_color(it->first, color.get_red(), color.get_green(), color.get_blue()); _c->change_entity_color(it->first, color.get_red(), color.get_green(), color.get_blue());
it++; it++;
} }
std::map<std::string, bool>::iterator it2 = _states_visible_changes.begin();
while(it2 != _states_visible_changes.end()){
_c->change_entity_visible(it2->first, it2->second);
it2++;
}
_states_changes.clear(); _states_changes.clear();
_states_visible_changes.clear();
emit settings_changed(); // Catch by at least the interface_graphic which will dispatch it to the classes which needs emit settings_changed(); // Catch by at least the interface_graphic which will dispatch it to the classes which needs
//hide(); //hide();
} }
...@@ -691,6 +742,7 @@ void Settings_window::on_use_palette_cb_stateChanged(){ ...@@ -691,6 +742,7 @@ void Settings_window::on_use_palette_cb_stateChanged(){
} }
void Settings_window::on_cancel_clicked() { void Settings_window::on_cancel_clicked() {
_states_visible_changes.clear();
_states_changes.clear(); _states_changes.clear();
_reload = false; _reload = false;
hide(); hide();
......
...@@ -68,6 +68,7 @@ private: ...@@ -68,6 +68,7 @@ private:
Core *_c; Core *_c;
std::map<std::string, Color> _states_changes; std::map<std::string, Color> _states_changes;
std::map<std::string, bool> _states_visible_changes;
bool _reload; bool _reload;
//used to check if leaving the tab needs an apply first when OK button is pressed //used to check if leaving the tab needs an apply first when OK button is pressed
bool _changed; bool _changed;
...@@ -80,14 +81,15 @@ private: ...@@ -80,14 +81,15 @@ private:
/*! /*!
* \brief add an event type to the table * \brief add an event type to the table
*/ */
void add_table_line(QTableWidget *table, const char *slot, void add_table_line(QTableWidget *table, const char *color_slot, const char *visible_slot,
int&, std::string, Color*, bool); int&, std::string, Color*, bool);
/*! /*!
* \brief Fill the state table with the states and theirs colors depending on the palette set. * \brief Fill the state table with the states and theirs colors depending on the palette set.
*/ */
void fill_table(QTableWidget *table, void fill_table(QTableWidget *table,
const char *slot, const char *color_slot,
const char *visible_slot,
const std::string pname, const std::string pname,
const std::string &palette_name ); const std::string &palette_name );
...@@ -123,6 +125,8 @@ private: ...@@ -123,6 +125,8 @@ private:
void color_changed(std::string name, QTableWidget *table, const QColor &qc); void color_changed(std::string name, QTableWidget *table, const QColor &qc);
void visible_changed(std::string name, QTableWidget *table, const bool checked);
public: public:
/*! /*!
* Default constructor * Default constructor
...@@ -156,6 +160,8 @@ private slots: ...@@ -156,6 +160,8 @@ private slots:
*/ */
void state_color_changed(const QColor &c); void state_color_changed(const QColor &c);
void state_visible_changed(int checked);
/*! /*!
* \fn event_types_color_changed(const QColor &c) * \fn event_types_color_changed(const QColor &c)
* \brief (event_types tab) Called when the user changes an object in the table. * \brief (event_types tab) Called when the user changes an object in the table.
...@@ -163,6 +169,8 @@ private slots: ...@@ -163,6 +169,8 @@ private slots:
*/ */
void event_types_color_changed(const QColor &c); void event_types_color_changed(const QColor &c);
void event_types_visible_changed(int checked);
/*! /*!
* \fn link_types_color_changed(const QColor &c) * \fn link_types_color_changed(const QColor &c)
* \brief (link_types tab) Called when the user changes an object in the table. * \brief (link_types tab) Called when the user changes an object in the table.
...@@ -170,6 +178,7 @@ private slots: ...@@ -170,6 +178,7 @@ private slots:
*/ */
void link_types_color_changed(const QColor &c); void link_types_color_changed(const QColor &c);
void link_types_visible_changed(int checked);
/*! /*!
* \fn on_add_state_btn_clicked() * \fn on_add_state_btn_clicked()
* \brief (state tab) Called when the user click on the add state button. * \brief (state tab) Called when the user click on the add state button.
......
...@@ -234,7 +234,8 @@ void Render_alternate::paintGL(){ ...@@ -234,7 +234,8 @@ void Render_alternate::paintGL(){
glUseProgram(s->getProgramID()); glUseProgram(s->getProgramID());
it_state->second->lock(); it_state->second->lock();
glUniformMatrix4fv(glGetUniformLocation(s->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp)); glUniformMatrix4fv(glGetUniformLocation(s->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glDrawArrays(GL_QUADS, 0, it_state->second->getNbVertex()); if(it_state->first->get_visible())
glDrawArrays(GL_QUADS, 0, it_state->second->getNbVertex());
it_state->second->unlock(); it_state->second->unlock();
it_state++; it_state++;
} }
...@@ -966,12 +967,29 @@ void Render_alternate::change_color(std::string entity, Element_col r, Element_c ...@@ -966,12 +967,29 @@ void Render_alternate::change_color(std::string entity, Element_col r, Element_c
} }
} }
void Render_alternate::change_visible(std::string entity, bool visible){
std::cout << "salut" << visible << std::endl;
std::map<EntityValue*, Shader*>::iterator it;
it = _states_shaders.begin();
while(it != _states_shaders.end()){
//std::cout << it->first->get_name().get_name() << std::endl;
//assert(it->first); // TODO: check why busy state exists and uncomment this assert
if(it->first && (it->first->get_name() == entity)){
it->first->set_visible(visible);
break;
}
it++;
}
}
void Render_alternate::reload_states(){ void Render_alternate::reload_states(){
std::map<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()){
if(it->first){ if(it->first){
it->first->reload_file_color(); it->first->reload_file_color();
it->first->set_visible(true);
Shader* s = it->second; Shader* s = it->second;
delete s; delete s;
s = new Shader(_glsl, it->first->get_used_color()->get_red(), s = new Shader(_glsl, it->first->get_used_color()->get_red(),
......
...@@ -125,6 +125,7 @@ private: ...@@ -125,6 +125,7 @@ private:
Vbo *_current; Vbo *_current;
std::map<EntityValue*, Vbo*> _states; std::map<EntityValue*, Vbo*> _states;
std::map<EntityValue*, Shader*> _states_shaders; std::map<EntityValue*, Shader*> _states_shaders;
std::map<EntityValue*, bool> _states_visible;
GLuint _textureID; GLuint _textureID;
/*! /*!
* \brief Offset of the vertical helper line * \brief Offset of the vertical helper line
...@@ -554,6 +555,8 @@ public slots: ...@@ -554,6 +555,8 @@ 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);
void change_visible(std::string entity, bool visible);
/*! /*!
* \brief reload state color from trace file * \brief reload state color from trace file
*/ */
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
/* -- */ /* -- */
using namespace std; using namespace std;
EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Value *> opt): _name(name), _type(type), _opt(opt), _display(true){ EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Value *> opt): _name(name), _type(type), _opt(opt), _visible(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"));
...@@ -77,7 +77,7 @@ EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Va ...@@ -77,7 +77,7 @@ EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Va
Palette *sp = Session::get_palette("palette", Session::get_current_palette("palette")); Palette *sp = Session::get_palette("palette", Session::get_current_palette("palette"));
Color* color = sp->get_color(type->get_name().to_string()); Color* color = sp->get_color(type->get_name().to_string());
if(!color) if(!color)
_display=false; _visible=false;
else else
_usedcolor = color; _usedcolor = color;
} }
...@@ -125,6 +125,14 @@ void EntityValue::reload_file_color(){ ...@@ -125,6 +125,14 @@ void EntityValue::reload_file_color(){
_usedcolor = _filecolor; _usedcolor = _filecolor;
} }
void EntityValue::set_visible(bool b){
_visible = b;
}
bool EntityValue::get_visible(){
return _visible;
}
EntityValue::~EntityValue(){ EntityValue::~EntityValue(){
_type = NULL; _type = NULL;
......
...@@ -61,7 +61,7 @@ private: ...@@ -61,7 +61,7 @@ private:
Color *_filecolor; Color *_filecolor;
Color *_usedcolor; Color *_usedcolor;
bool _display; bool _visible;
public: public:
/*! /*!
...@@ -95,6 +95,10 @@ public: ...@@ -95,6 +95,10 @@ public:
void set_used_color(Color *c); void set_used_color(Color *c);
void set_visible(bool b);
bool get_visible();
void reload_file_color(); void reload_file_color();
virtual ~EntityValue(); virtual ~EntityValue();
......
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