Commit 81284e56 authored by Mathieu Faverge's avatar Mathieu Faverge

Simplify EntityValue creation

parent 758bdcae
......@@ -123,7 +123,6 @@ public:
virtual ~GanttDiagram(){
}
/***********************************
*
* Building functions.
......
......@@ -55,7 +55,13 @@
/* -- */
using namespace std;
EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Value *> opt): _name(name), _type(type), _opt(opt), _visible(true){
EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Value *> opt)
: _name(name), _type(type), _opt(opt), _visible(true)
{
Palette *sp = NULL;
Color *color = NULL;
Color *new_color;
std::string palette_name = "default";
// 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,60 +77,38 @@ EntityValue::EntityValue(const Name &name, EntityType *type, map<std::string, Va
// Set the used color to the color selected in the palette if existing, otherwise equal to the filecolor.
_usedcolor = _filecolor;
Palette *sp = NULL;
Color *color = NULL;
Color *new_color;
switch (type->get_class()) {
case _EntityClass_State:
//if(Session::get_use_palette("palette")){
sp = Session::get_palette("palette", Session::get_current_palette("palette"));
color = sp->get_color(name.get_name());
if(color != NULL){
std::cout << name.get_alias() << " " << color->get_red() << " " << color->get_green() << " " << color->get_blue() << std::endl;
//color is used in palette class. It will be free'd when modifying palette (remove_palette -> create_palette) but we don't want _usedcolor to be free'd at the same moment. So we use new_color to make a copy
new_color = new Color(color->get_red(), color->get_green(), color->get_blue());
_usedcolor = new_color;
}
if(sp->is_visible(name.get_name()))
_visible=true;
else
_visible = false;
palette_name = "palette";
break;
case _EntityClass_Link:
//if(Session::get_use_palette("palette")){
sp = Session::get_palette("link_types", Session::get_current_palette("link_types"));
color = sp->get_color(name.get_name());
if(color != NULL){
std::cout << name.get_alias() << " " << color->get_red() << " " << color->get_green() << " " << color->get_blue() << std::endl;
//color is used in palette class. It will be free'd when modifying palette (remove_palette -> create_palette) but we don't want _usedcolor to be free'd at the same moment. So we use new_color to make a copy
new_color = new Color(color->get_red(), color->get_green(), color->get_blue());
_usedcolor = new_color;
}
if(sp->is_visible(name.get_name()))
_visible=true;
else
_visible = false;
palette_name = "link_types";
break;
case _EntityClass_Event:
sp = Session::get_palette("event_types", Session::get_current_palette("event_types"));
color = sp->get_color(name.get_name());
if(color != NULL){
std::cout << name.get_alias() << " " << color->get_red() << " " << color->get_green() << " " << color->get_blue() << std::endl;
//color is used in palette class. It will be free'd when modifying palette (remove_palette -> create_palette) but we don't want _usedcolor to be free'd at the same moment. So we use new_color to make a copy
new_color = new Color(color->get_red(), color->get_green(), color->get_blue());
_usedcolor = new_color;
}
if(sp->is_visible(name.get_name()))
_visible=true;
else
_visible = false;
palette_name = "event_types";
break;
case _EntityClass_Variable:
break;
default:
std::cerr << "Error unsupported type for Entity value" << std::endl;
break;
}
}
if ( type->get_class() != _EntityClass_Variable ) {
sp = Session::get_palette( palette_name,
Session::get_current_palette( palette_name ) );
color = sp->get_color( name.get_name() );
if( color != NULL ) {
_usedcolor = new Color( color );
}
if( sp->is_visible( name.get_name() ) ) {
_visible = true;
}
else {
_visible = false;
}
}
}
EntityValue::~EntityValue()
......
......@@ -68,6 +68,10 @@ Color::Color(const Color &c) : Value(c), _r(c._r), _g(c._g), _b(c._b) {
_is_correct = c._is_correct;
}
Color::Color(const Color *c) : Value(*c), _r(c->_r), _g(c->_g), _b(c->_b) {
_is_correct = c->_is_correct;
}
Color::Color(const std::string &in) {
string separated_color[3];
string temp = in;
......
......@@ -73,16 +73,9 @@ public:
* \brief Constructor
*/
Color(double, double, double);
/*!
* \brief Constructor
*/
Color(const std::string &);
/*!
* \brief Constructor
*/
Color(const Color &);
Color(const Color *);
/*!
* \fn to_string() const
......
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