Commit ae6ee410 authored by Kevin Coulomb's avatar Kevin Coulomb

Modification de la structure de donnée pour utiliser les arbres sur les

etats aussi
parent eae6c06d
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Container::Container(Name name, Date creation_time, ContainerType *type, Container *parent): Container::Container(Name name, Date creation_time, ContainerType *type, Container *parent):
_name(name), _creation_time(creation_time), _destruction_time(0.0), _type(type), _parent(parent), _name(name), _creation_time(creation_time), _destruction_time(0.0), _type(type), _parent(parent),
_n_variables(0), _event_tree(0), _n_events(0), _n_states(0) { _n_variables(0), _event_tree(0), _state_tree(0), _n_events(0), _n_states(0) {
} }
template <class T> template <class T>
...@@ -20,7 +20,8 @@ Container::~Container() { ...@@ -20,7 +20,8 @@ Container::~Container() {
clear_list<Container>(_children); clear_list<Container>(_children);
// Delete states // Delete states
clear_list<State>(_states); // clear_list<State>(_states);
delete _state_tree;
// Delete events // Delete events
delete _event_tree; delete _event_tree;
...@@ -163,8 +164,8 @@ Date Container::get_destruction_time() const { ...@@ -163,8 +164,8 @@ Date Container::get_destruction_time() const {
return _destruction_time; return _destruction_time;
} }
const list<State *> *Container::get_states() const { BinaryTree<State> *Container::get_states() const {
return &_states; return _state_tree;
} }
BinaryTree<Event> *Container::get_events() const { BinaryTree<Event> *Container::get_events() const {
...@@ -195,5 +196,6 @@ void Container::finish(const Date &time) { ...@@ -195,5 +196,6 @@ void Container::finish(const Date &time) {
if (_destruction_time.get_value() == 0.0) if (_destruction_time.get_value() == 0.0)
destroy(time); destroy(time);
_event_tree = new BinaryTree<Event>(_events, _n_events); _event_tree = new BinaryTree<Event>(_events, _n_events);
_state_tree = new BinaryTree<State>(_states,_n_states);//MODIF
} }
...@@ -40,6 +40,7 @@ private: ...@@ -40,6 +40,7 @@ private:
list<Container *> _children; list<Container *> _children;
unsigned int _n_states; unsigned int _n_states;
list<State *> _states; list<State *> _states;
BinaryTree<State> *_state_tree;//MODIF
unsigned int _n_events; unsigned int _n_events;
list<Event *> _events; list<Event *> _events;
BinaryTree<Event> *_event_tree; BinaryTree<Event> *_event_tree;
...@@ -215,7 +216,7 @@ public: ...@@ -215,7 +216,7 @@ public:
* \fn get_states() const * \fn get_states() const
* \brief Get the state list * \brief Get the state list
*/ */
const list<State *> *get_states() const; BinaryTree<State> *get_states() const;// MODIF -> enleve * du template/ du const
/*! /*!
* \fn get_events() const * \fn get_events() const
......
...@@ -176,7 +176,7 @@ public: ...@@ -176,7 +176,7 @@ public:
_entity_containers.push_back(container); _entity_containers.push_back(container);
} }
// Use one line dor each variable // Use one line for each variable
if (container->get_variable_number() > 0) { if (container->get_variable_number() > 0) {
_variable_containers.push_back(container); _variable_containers.push_back(container);
size += container->get_variable_number(); size += container->get_variable_number();
...@@ -213,17 +213,15 @@ public: ...@@ -213,17 +213,15 @@ public:
*/ */
inline void browse_entities(T* draw_object) { inline void browse_entities(T* draw_object) {
const Container *container; const Container *container;
const list<State *> *state_list; BinaryTree<State> *state_tree;//MODIF
State *state;
BinaryTree<Event> *event_tree; BinaryTree<Event> *event_tree;
Event *event;
const list<Link *> *link_list; const list<Link *> *link_list;
Link *link; Link *link;
const map<VariableType *, Variable *> *variable_map; const map<VariableType *, Variable *> *variable_map;
Variable *var; Variable *var;
const list<pair<Date, Double> > *variable_values; const list<pair<Date, Double> > *variable_values;
const map<std::string, Value *> *extra_fields; // const map<std::string, Value *> *extra_fields;
const Color *color; // const Color *color;
int position; int position;
draw_object->start_draw_states(); draw_object->start_draw_states();
...@@ -233,36 +231,42 @@ public: ...@@ -233,36 +231,42 @@ public:
container = *c; container = *c;
position = _container_positions[container]; position = _container_positions[container];
state_list = container->get_states(); state_tree = container->get_states();
event_tree = container->get_events(); event_tree = container->get_events();
if (!state_list->empty() || !event_tree->empty()) { if (!state_tree->empty() || !event_tree->empty()) {
// Browse states // Browse states
for (list<State *>::const_iterator i = state_list->begin();
i != state_list->end();
i++) { DrawTree<T, State>(draw_object, position, 0.0,
_container_height, _container_v_space, _state_height, _state_v_space)
state = *i; .draw_tree(state_tree, &Interval(Date(0.0), Date(500.0)));
map<std::string, Value *>::const_iterator field; /*
for (list<State *>::const_iterator i = state_list->begin();
// Search the color i != state_list->end();
if (state->get_value() && i++) {
!state->get_value()->get_extra_fields()->empty() &&
((field = state->get_value()->get_extra_fields()->find(std::string("Color"))) != extra_fields->end())) { state = *i;
/* Call the object state drawing function with the state color */ map<std::string, Value *>::const_iterator field;
color = (const Color *)(*field).second;
draw_state(draw_object, state->get_start_time().get_value(), state->get_end_time().get_value(), position, // Search the color
color->get_red(), color->get_green(), color->get_blue()); if (state->get_value() &&
} !state->get_value()->get_extra_fields()->empty() &&
else { ((field = state->get_value()->get_extra_fields()->find(std::string("Color"))) != extra_fields->end())) {
/* Call the object state drawing function with default color */ /* Call the object state drawing function with the state color */
draw_state(draw_object, state->get_start_time().get_value(), state->get_end_time().get_value(), position, 0.7, 0.7, 0.75); /* color = (const Color *)(*field).second;
} draw_state(draw_object, state->get_start_time().get_value(), state->get_end_time().get_value(), position,
}/* end for */ color->get_red(), color->get_green(), color->get_blue());
}
else {
/* Call the object state drawing function with default color */
/* draw_state(draw_object, state->get_start_time().get_value(), state->get_end_time().get_value(), position, 0.7, 0.7, 0.75);
}
}/* end for */
// Browse events // Browse events
DrawTree<T, Event>(draw_object, position, 0.0, DrawTree<T, Event>(draw_object, position, 0.0,
_container_height, _container_v_space, _state_height, _state_v_space) _container_height, _container_v_space, _state_height, _state_v_space)
.draw_tree(event_tree, &Interval(Date(0.0), Date(500.0))); .draw_tree(event_tree, &Interval(Date(0.0), Date(500.0)));
/*for (list<Event *>::const_iterator i = event_list->begin(); /*for (list<Event *>::const_iterator i = event_list->begin();
i != event_list->end(); i != event_list->end();
i++) { i++) {
...@@ -348,10 +352,10 @@ public: ...@@ -348,10 +352,10 @@ 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(T *draw_object, double starttime, double endtime, int position, double r, double g, double b) { /* inline void draw_state(T *draw_object, double starttime, double endtime, int position, double r, double g, double b) {
Element_pos y = position*(_container_height+_container_v_space) + _container_v_space/2; Element_pos y = position*(_container_height+_container_v_space) + _container_v_space/2;
draw_object->draw_state(starttime, endtime, y, _state_height, r, g, b); draw_object->draw_state(starttime, endtime, y, _state_height, r, g, b);
} }*/
/*! /*!
* \brief Draw an event * \brief Draw an event
......
This diff is collapsed.
...@@ -25,3 +25,6 @@ const EntityValue *State::get_value() const { ...@@ -25,3 +25,6 @@ const EntityValue *State::get_value() const {
return _value; return _value;
} }
const Date State::get_time() const{
return _start;
}
...@@ -59,6 +59,12 @@ public: ...@@ -59,6 +59,12 @@ public:
* \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;
/*!
* \fn get_time()
* \brief Get the time of the state
*/
const Date get_time() const;
}; };
#endif #endif
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
// Calculate n and m as size = 2^n - 1 + m and m < 2^n // Calculate n and m as size = 2^n - 1 + m and m < 2^n
int n = 0; int n = 0;
int a = 1; unsigned int a = 1;
while (size >= 2*a - 1) { while (size >= 2*a - 1) {
a *= 2; a *= 2;
n++; n++;
......
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