Commit f04c1140 authored by Clément Vuchener's avatar Clément Vuchener

Ajout du support des couleurs pour les états

parent 4dea3b8f
......@@ -25,7 +25,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
String dest_container;
String key;
vector<Value *> extra_fields;
map<std::string, Value *> extra_fields;
unsigned int i = 1;
vector<Field> fields = definition.get_fields();
......@@ -109,8 +109,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
else {
if(fields[i-1]._type == "string") {
String value = current_value;
extra_fields.push_back(&value);
extra_fields[fields[i-1]._name] = new String(current_value);
}
else if(fields[i-1]._type == "double") {
Double value;
......@@ -119,7 +118,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
//cerr << "warning : incompatible value : " << current_value << endl;
return;
}
extra_fields.push_back(&value);
extra_fields[fields[i-1]._name] = new Double(value);
}
else if(fields[i-1]._type == "hex") {
Hex value;
......@@ -128,7 +127,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
//cerr << "warning : incompatible value : " << current_value << endl;
return;
}
extra_fields.push_back(&value);
extra_fields[fields[i-1]._name] = new Hex(value);
}
else if(fields[i-1]._type == "date") {
Date value;
......@@ -137,7 +136,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
//cerr << "warning : incompatible value : " << current_value << endl;
return;
}
extra_fields.push_back(&value);
extra_fields[fields[i-1]._name] = new Date(value);
}
else if(fields[i-1]._type == "int") {
Integer value;
......@@ -146,7 +145,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
//cerr << "warning : incompatible value : " << current_value << endl;
return;
}
extra_fields.push_back(&value);
extra_fields[fields[i-1]._name] = new Integer(value);
}
else if(fields[i-1]._type == "color") {
Color value;
......@@ -155,7 +154,7 @@ void ParserEventDecoder::store_event(const Definition &definition, Line &line, T
//cerr << "warning : incompatible value : " << current_value << endl;
return;
}
extra_fields.push_back(&value);
extra_fields[fields[i-1]._name] = new Color(value);
}
else {
Error::set_and_print_warning(Error::_UNKNOWN_TYPE_IN_EVENT + current_value, line.get_line_count());
......
......@@ -294,6 +294,8 @@ public:
Event *event;
const list<Link *> *link_list;
Link *link;
const map<std::string, Value *> *extra_fields;
const Color *color;
Element_count i;/* for the level (y axis) of the states */
i = 0;
......@@ -308,8 +310,21 @@ public:
state = *it;
Element_pos base = ((Element_pos)i)*_container_height+((Element_pos)i)*_container_v_space+_container_v_space;
/* Call the object state drawing function */
draw_object->draw_state(state->get_start_time().get_value(), state->get_end_time().get_value(), base, _state_height, 0.7, 0.7, 0.75);
// Search the color
extra_fields = state->get_value()->get_extra_fields();
map<std::string, Value *>::const_iterator field = extra_fields->find(std::string("Color"));
if (field == extra_fields->end()) {
/* Call the object state drawing function with default color */
draw_object->draw_state(state->get_start_time().get_value(), state->get_end_time().get_value(), base, _state_height, 0.7, 0.7, 0.75);
}
else {
/* Call the object state drawing function with the state color */
color = (const Color *)(*field).second;
draw_object->draw_state(state->get_start_time().get_value(), state->get_end_time().get_value(),
base, _state_height,
color->get_red(), color->get_green(), color->get_blue());
}
}/* end for */
// Browse events
......
#include "EntityValue.hpp"
EntityValue::EntityValue(const Name &name, EntityType *type): _name(name), _type(type) {
EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Value *> opt): _name(name), _type(type), _opt(opt) {
}
......@@ -11,3 +11,8 @@ Name EntityValue::get_name() const {
const EntityType *EntityValue::get_type() const {
return _type;
}
const map<std::string, Value *> *EntityValue::get_extra_fields() const {
return &_opt;
}
......@@ -10,6 +10,10 @@
*
*/
#include "values/Value.hpp"
#include <map>
using std::map;
class EntityValue;
#include "EntityType.hpp"
......@@ -24,12 +28,14 @@ class EntityValue {
private:
Name _name;
EntityType *_type;
map<std::string, Value *> _opt;
public:
EntityValue(const Name &name, EntityType *type);
EntityValue(const Name &name, EntityType *type, map<std::string, Value *> opt);
Name get_name() const;
const EntityType *get_type() const;
const map<std::string, Value *> *get_extra_fields() const;
};
#endif
......@@ -16,7 +16,7 @@ Trace::~Trace() {
}
}
void Trace::define_container_type(Name &name, ContainerType *parent, const vector<Value *> &opt) {
void Trace::define_container_type(Name &name, ContainerType *parent, const map<std::string, Value *> &opt) {
ContainerType *type = new ContainerType(name, parent);
if (parent)
parent->add_child(type);
......@@ -24,7 +24,7 @@ void Trace::define_container_type(Name &name, ContainerType *parent, const vecto
_root_container_types.push_back(type);
}
void Trace::create_container(Date &time, Name &name, ContainerType *type, Container *parent, const vector<Value *> &opt) {
void Trace::create_container(Date &time, Name &name, ContainerType *type, Container *parent, const map<std::string, Value *> &opt) {
if (!type)
return;
......@@ -35,73 +35,73 @@ void Trace::create_container(Date &time, Name &name, ContainerType *type, Contai
_root_containers.push_back(cont);
}
void Trace::destroy_container(Date &time, Container *cont, ContainerType *type, const vector<Value *> &opt) {
void Trace::destroy_container(Date &time, Container *cont, ContainerType *type, const map<std::string, Value *> &opt) {
if (cont)
cont->destroy(time);
}
void Trace::define_event_type(Name &name, ContainerType *container_type, const vector<Value *> &opt) {
void Trace::define_event_type(Name &name, ContainerType *container_type, const map<std::string, Value *> &opt) {
if (container_type)
_event_types.push_back(new EventType(name, container_type));
}
void Trace::define_state_type(Name &name, ContainerType *container_type, const vector<Value *> &opt) {
void Trace::define_state_type(Name &name, ContainerType *container_type, const map<std::string, Value *> &opt) {
if (container_type)
_state_types.push_back(new StateType(name, container_type));
}
void Trace::define_variable_type(Name &name, ContainerType *container_type, const vector<Value *> &opt) {
void Trace::define_variable_type(Name &name, ContainerType *container_type, const map<std::string, Value *> &opt) {
}
void Trace::define_link_type(Name &name, ContainerType *ancestor, ContainerType *source, ContainerType *destination, const vector<Value *> &opt) {
void Trace::define_link_type(Name &name, ContainerType *ancestor, ContainerType *source, ContainerType *destination, const map<std::string, Value *> &opt) {
if (ancestor)
_link_types.push_back(new LinkType(name, ancestor, source, destination));
}
void Trace::define_entity_value(Name &name, EntityType *entity_type, const vector<Value *> &opt) {
void Trace::define_entity_value(Name &name, EntityType *entity_type, const map<std::string, Value *> &opt) {
if (entity_type)
entity_type->add_value(new EntityValue(name, entity_type));
entity_type->add_value(new EntityValue(name, entity_type, opt));
}
void Trace::set_state(Date &time, StateType *type, Container *container, EntityValue *value, const vector<Value *> &opt) {
void Trace::set_state(Date &time, StateType *type, Container *container, EntityValue *value, const map<std::string, Value *> &opt) {
if (container && type && value)
container->set_state(time, type, value);
}
void Trace::push_state(Date &time, StateType *type, Container *container, EntityValue *value, const vector<Value *> &opt) {
void Trace::push_state(Date &time, StateType *type, Container *container, EntityValue *value, const map<std::string, Value *> &opt) {
if (container && type && value)
container->push_state(time, type, value);
}
void Trace::pop_state(Date &time, StateType *type, Container *container, const vector<Value *> &opt) {
void Trace::pop_state(Date &time, StateType *type, Container *container, const map<std::string, Value *> &opt) {
if (container)
container->pop_state(time);
}
void Trace::new_event(Date &time, EventType *type, Container *container, EntityValue *value, const vector<Value *> &opt) {
void Trace::new_event(Date &time, EventType *type, Container *container, EntityValue *value, const map<std::string, Value *> &opt) {
if (container)
container->new_event(time, type, value);
}
void Trace::set_variable(Date &time, VariableType *type, Container *container, Double value, const vector<Value *> &opt) {
void Trace::set_variable(Date &time, VariableType *type, Container *container, Double value, const map<std::string, Value *> &opt) {
}
void Trace::add_variable(Date &time, VariableType *type, Container *container, Double value, const vector<Value *> &opt) {
void Trace::add_variable(Date &time, VariableType *type, Container *container, Double value, const map<std::string, Value *> &opt) {
}
void Trace::sub_variable(Date &time, VariableType *type, Container *container, Double value, const vector<Value *> &opt) {
void Trace::sub_variable(Date &time, VariableType *type, Container *container, Double value, const map<std::string, Value *> &opt) {
}
void Trace::start_link(Date &time, LinkType *type, Container *ancestor, Container *source, EntityValue *value, String key, const vector<Value *> &opt) {
void Trace::start_link(Date &time, LinkType *type, Container *ancestor, Container *source, EntityValue *value, String key, const map<std::string, Value *> &opt) {
if (ancestor)
ancestor->start_link(time, type, source, value, key);
}
void Trace::end_link(Date &time, LinkType *type, Container *ancestor, Container *destination, EntityValue *value, String key, const vector<Value *> &opt) {
void Trace::end_link(Date &time, LinkType *type, Container *ancestor, Container *destination, EntityValue *value, String key, const map<std::string, Value *> &opt) {
if (ancestor)
ancestor->end_link(time, destination, key);
}
......
......@@ -66,7 +66,7 @@ public :
*\param container_type_parent an object that can contain a name, an alias or both
*
*/
void define_container_type(Name &alias, ContainerType *container_type_parent, const vector<Value *> &opt);
void define_container_type(Name &alias, ContainerType *container_type_parent, const map<std::string, Value *> &opt);
/*!
*
......@@ -80,7 +80,7 @@ public :
*\param String : the parent of the container
*
*/
void create_container(Date &time, Name &alias, ContainerType *type, Container *parent, const vector<Value *> &opt);
void create_container(Date &time, Name &alias, ContainerType *type, Container *parent, const map<std::string, Value *> &opt);
/*!
*
......@@ -92,7 +92,7 @@ public :
*\param type the type of the container
*
*/
void destroy_container(Date &time, Container *cont, ContainerType *type, const vector<Value *> &opt);
void destroy_container(Date &time, Container *cont, ContainerType *type, const map<std::string, Value *> &opt);
/*!
......@@ -104,7 +104,7 @@ public :
*\param container_type the type of the container
*
*/
void define_event_type(Name &alias, ContainerType *container_type, const vector<Value *> &opt);
void define_event_type(Name &alias, ContainerType *container_type, const map<std::string, Value *> &opt);
/*!
......@@ -117,7 +117,7 @@ public :
*
*
*/
void define_state_type(Name &alias, ContainerType *container_type, const vector<Value *> &opt);
void define_state_type(Name &alias, ContainerType *container_type, const map<std::string, Value *> &opt);
/*!
......@@ -129,7 +129,7 @@ public :
*\param container_type the type of the container
*
*/
void define_variable_type(Name &alias, ContainerType *container_type, const vector<Value *> &opt);
void define_variable_type(Name &alias, ContainerType *container_type, const map<std::string, Value *> &opt);
/*!
......@@ -143,7 +143,7 @@ public :
*\param destination the type of the container where the link goes
*
*/
void define_link_type(Name &alias, ContainerType *ancestor, ContainerType *source, ContainerType *destination, const vector<Value *> &opt);
void define_link_type(Name &alias, ContainerType *ancestor, ContainerType *source, ContainerType *destination, const map<std::string, Value *> &opt);
/*!
......@@ -155,7 +155,7 @@ public :
*\param entity_type the type of the entity
*
*/
void define_entity_value(Name &alias, EntityType *entity_type, const vector<Value *> &opt);
void define_entity_value(Name &alias, EntityType *entity_type, const map<std::string, Value *> &opt);
/*!
......@@ -169,7 +169,7 @@ public :
*\param value the new value of the state
*
*/
void set_state(Date &time, StateType *type, Container *container, EntityValue *value, const vector<Value *> &opt);
void set_state(Date &time, StateType *type, Container *container, EntityValue *value, const map<std::string, Value *> &opt);
/*!
......@@ -183,7 +183,7 @@ public :
*\param String : the new value of the state
*
*/
void push_state(Date &time, StateType *type, Container *container, EntityValue *value, const vector<Value *> &opt);
void push_state(Date &time, StateType *type, Container *container, EntityValue *value, const map<std::string, Value *> &opt);
/*!
......@@ -196,7 +196,7 @@ public :
*\param container the container
*
*/
void pop_state(Date &time, StateType *type, Container *container, const vector<Value *> &opt);
void pop_state(Date &time, StateType *type, Container *container, const map<std::string, Value *> &opt);
/*!
......@@ -210,7 +210,7 @@ public :
*\param value the value of the event
*
*/
void new_event(Date &time, EventType *type, Container *container, EntityValue *value, const vector<Value *> &opt);
void new_event(Date &time, EventType *type, Container *container, EntityValue *value, const map<std::string, Value *> &opt);
/*!
......@@ -224,7 +224,7 @@ public :
*\param value the value of the variable
*
*/
void set_variable(Date &time, VariableType *type, Container *container, Double value, const vector<Value *> &opt);
void set_variable(Date &time, VariableType *type, Container *container, Double value, const map<std::string, Value *> &opt);
/*!
......@@ -238,7 +238,7 @@ public :
*\param value the value of the variable
*
*/
void add_variable(Date &time, VariableType *type, Container *container, Double value, const vector<Value *> &opt);
void add_variable(Date &time, VariableType *type, Container *container, Double value, const map<std::string, Value *> &opt);
/*!
......@@ -252,7 +252,7 @@ public :
*\param value the value of the variable
*
*/
void sub_variable(Date &time, VariableType *type, Container *container, Double value, const vector<Value *> &opt);
void sub_variable(Date &time, VariableType *type, Container *container, Double value, const map<std::string, Value *> &opt);
/*!
......@@ -267,7 +267,7 @@ public :
*\param value the value of the variable
*
*/
void start_link(Date &time, LinkType *type, Container *ancestor, Container *source, EntityValue *value, String key, const vector<Value *> &opt);
void start_link(Date &time, LinkType *type, Container *ancestor, Container *source, EntityValue *value, String key, const map<std::string, Value *> &opt);
/*!
......@@ -282,7 +282,7 @@ public :
*\param value the value of the variable
*
*/
void end_link(Date &time, LinkType *type, Container *ancestor, Container *destination, EntityValue *value, String key, const vector<Value *> &opt);
void end_link(Date &time, LinkType *type, Container *ancestor, Container *destination, EntityValue *value, String key, const map<std::string, Value *> &opt);
/*!
......
......@@ -60,4 +60,16 @@ bool Color::replace_in_string(std::string &characters, char to_replace, char rep
}
return has_change;
}
double Color::get_red() const {
return _r;
}
double Color::get_green() const {
return _g;
}
double Color::get_blue() const {
return _b;
}
......@@ -58,6 +58,30 @@ public:
*
*/
std::string to_string() const;
/*!
*
* \fn get_red() const
* \return red value
*
*/
double get_red() const;
/*!
*
* \fn get_green() const;
* \return green value
*
*/
double get_green() const;
/*!
*
* \fn get_blue() const;
* \return blue value
*
*/
double get_blue() const;
private:
/*!
......
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