diff --git a/src/trace/Container.cpp b/src/trace/Container.cpp index 1d3ec8247963f7b7d6c703e7ee740641ca6ad78a..7e48b58862bb9d0446b0204095b29225f37557ba 100644 --- a/src/trace/Container.cpp +++ b/src/trace/Container.cpp @@ -3,7 +3,7 @@ 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), - _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> @@ -20,7 +20,8 @@ Container::~Container() { clear_list<Container>(_children); // Delete states - clear_list<State>(_states); + // clear_list<State>(_states); + delete _state_tree; // Delete events delete _event_tree; @@ -163,8 +164,8 @@ Date Container::get_destruction_time() const { return _destruction_time; } -const list<State *> *Container::get_states() const { - return &_states; +BinaryTree<State> *Container::get_states() const { + return _state_tree; } BinaryTree<Event> *Container::get_events() const { @@ -195,5 +196,6 @@ void Container::finish(const Date &time) { if (_destruction_time.get_value() == 0.0) destroy(time); _event_tree = new BinaryTree<Event>(_events, _n_events); + _state_tree = new BinaryTree<State>(_states,_n_states);//MODIF } diff --git a/src/trace/Container.hpp b/src/trace/Container.hpp index 81cd023dea18fb91c39bfd7a4c3f2f6a83e0a860..1a899a4e9df6bf5e78fb7d35ae79980a01b0cfe4 100644 --- a/src/trace/Container.hpp +++ b/src/trace/Container.hpp @@ -40,6 +40,7 @@ private: list<Container *> _children; unsigned int _n_states; list<State *> _states; + BinaryTree<State> *_state_tree;//MODIF unsigned int _n_events; list<Event *> _events; BinaryTree<Event> *_event_tree; @@ -215,7 +216,7 @@ public: * \fn get_states() const * \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 diff --git a/src/trace/DrawTrace.hpp b/src/trace/DrawTrace.hpp index 0d4e545f61e0694faed6f98364c6a554c8357af1..e5ee07c1efec970d4d9a530419674255b8a56a44 100644 --- a/src/trace/DrawTrace.hpp +++ b/src/trace/DrawTrace.hpp @@ -176,7 +176,7 @@ public: _entity_containers.push_back(container); } - // Use one line dor each variable + // Use one line for each variable if (container->get_variable_number() > 0) { _variable_containers.push_back(container); size += container->get_variable_number(); @@ -213,17 +213,15 @@ public: */ inline void browse_entities(T* draw_object) { const Container *container; - const list<State *> *state_list; - State *state; + BinaryTree<State> *state_tree;//MODIF BinaryTree<Event> *event_tree; - Event *event; const list<Link *> *link_list; Link *link; const map<VariableType *, Variable *> *variable_map; Variable *var; const list<pair<Date, Double> > *variable_values; - const map<std::string, Value *> *extra_fields; - const Color *color; + // const map<std::string, Value *> *extra_fields; + // const Color *color; int position; draw_object->start_draw_states(); @@ -233,36 +231,42 @@ public: container = *c; position = _container_positions[container]; - state_list = container->get_states(); - event_tree = container->get_events(); - if (!state_list->empty() || !event_tree->empty()) { - // Browse states - for (list<State *>::const_iterator i = state_list->begin(); - i != state_list->end(); - i++) { - - state = *i; - map<std::string, Value *>::const_iterator field; - - // Search the color - if (state->get_value() && - !state->get_value()->get_extra_fields()->empty() && - ((field = state->get_value()->get_extra_fields()->find(std::string("Color"))) != extra_fields->end())) { - /* Call the object state drawing function with the state color */ - color = (const Color *)(*field).second; - draw_state(draw_object, state->get_start_time().get_value(), state->get_end_time().get_value(), position, - 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 */ + state_tree = container->get_states(); + event_tree = container->get_events(); + if (!state_tree->empty() || !event_tree->empty()) { + // Browse states + + + DrawTree<T, State>(draw_object, position, 0.0, + _container_height, _container_v_space, _state_height, _state_v_space) + .draw_tree(state_tree, &Interval(Date(0.0), Date(500.0))); + /* + for (list<State *>::const_iterator i = state_list->begin(); + i != state_list->end(); + i++) { + + state = *i; + map<std::string, Value *>::const_iterator field; + + // Search the color + if (state->get_value() && + !state->get_value()->get_extra_fields()->empty() && + ((field = state->get_value()->get_extra_fields()->find(std::string("Color"))) != extra_fields->end())) { + /* Call the object state drawing function with the state color */ + /* color = (const Color *)(*field).second; + draw_state(draw_object, state->get_start_time().get_value(), state->get_end_time().get_value(), position, + 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 DrawTree<T, Event>(draw_object, position, 0.0, - _container_height, _container_v_space, _state_height, _state_v_space) - .draw_tree(event_tree, &Interval(Date(0.0), Date(500.0))); + _container_height, _container_v_space, _state_height, _state_v_space) + .draw_tree(event_tree, &Interval(Date(0.0), Date(500.0))); /*for (list<Event *>::const_iterator i = event_list->begin(); i != event_list->end(); i++) { @@ -348,10 +352,10 @@ public: * \param g Green 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; draw_object->draw_state(starttime, endtime, y, _state_height, r, g, b); - } + }*/ /*! * \brief Draw an event diff --git a/src/trace/DrawTree.hpp b/src/trace/DrawTree.hpp index 5605961b0d469508a55d803f36f671939a62b33e..a3433b044c348b623aaebe2f9a87cd89c3c1af2f 100644 --- a/src/trace/DrawTree.hpp +++ b/src/trace/DrawTree.hpp @@ -4,7 +4,7 @@ #include "tree/BinaryTree.hpp" #include "Event.hpp" - +#include <iostream> template<class D, class E> class DrawTree { private: @@ -19,6 +19,9 @@ private: Element_pos _state_v_space; public: + /*! + *\brief Default constructor + */ DrawTree(D *draw_object, int position, double min_size, Element_pos container_height, Element_pos container_v_space, Element_pos state_height, Element_pos state_v_space): @@ -27,12 +30,11 @@ public: _state_height(state_height), _state_v_space(state_v_space) { } - /* - *\fn browse_draw_tree_root(E * draw_object, Interval * I, BinaryTree * tree) - *\brief Function called to draw on ViTE the elements of a tree - *\param draw_object : - *\param I : The interval we have to draw the tree - *\param tree : The tree we want to draw + /*! + * \fn browse_draw_tree_root( BinaryTree * tree, Interval * I) + * \brief Function called to draw on ViTE the elements of a tree + * \param tree : The tree we want to draw + * \param I : The interval we have to draw the tree */ void draw_tree(BinaryTree<E> *tree, Interval *I){ Node<E> *node = tree->get_root(); @@ -40,16 +42,16 @@ public: browse_tree(I, node); } - /* - *\fn browse_draw_tree(E * draw_object, Interval * I, Node * node) - *\brief Function called to draw on ViTE a node - *\param draw_object : - *\param I : The interval we have to draw node - *\param node : The node we want to draw + /*! + * \fn browse_draw_tree( Interval * I, Node * node) + * \brief Function called to draw on ViTE a node + * \param I : The interval we have to draw node + * \param node : The node we want to draw */ void browse_tree(Interval * I, Node<E> * node); /*! + * \fn draw_state(double starttime, double endtime, double r, double g, double b) * \brief Draw a state * \param starttime Time when the state begins * \param endtime Time when the state ends @@ -63,6 +65,7 @@ public: } /*! + * \fn draw_event(double time) * \brief Draw an event * \param time Time of the event */ @@ -71,7 +74,7 @@ public: _draw_object->draw_event(time, y, _state_height); } - /* + /*! * \fn display_busy(Interval *I) * \brief Function that display a purple squarre in the interval selected */ @@ -92,19 +95,57 @@ struct DrawNode<D, Event> { } }; + +template<class D> +struct DrawNode<D, State> { + static void draw_node(DrawTree<D, State> *draw, Node<State> *node) { + if(node){ + map<std::string, Value *>::const_iterator field; + const State * state = node->get_element(); + const map<std::string, Value *> *extra_fields; + const Color *color; + extra_fields = state->get_value()->get_extra_fields(); + // Search the color + if (state->get_value() && + !state->get_value()->get_extra_fields()->empty() && + ((field = state->get_value()->get_extra_fields()->find(std::string("Color"))) != extra_fields->end())) { + /* Call the object state drawing function with the state color */ + color = (const Color *)(*field).second; + draw->draw_state(state->get_start_time().get_value(), state->get_end_time().get_value(), + color->get_red(), color->get_green(), color->get_blue()); + } + else { + /* Call the object state drawing function with default color */ + draw->draw_state( state->get_start_time().get_value(), state->get_end_time().get_value(), 0.7, 0.7, 0.75); + } + } + else{ + std::cerr<<"Error Using an empty node whereas should not be NULL"<<std::endl; + } + } +}; + template<class D, class E> +/*! + *\fn browse_tree(Interval * I, Node<E> * node) + *\brief Function that browses a tree to display + *\param I : The interval we have to display node + *\param Node : The node in the tree we want to display + */ void DrawTree<D, E>::browse_tree(Interval * I, Node<E> * node) { + bool displayed = false;// To remember if node has already been displayed int n_children; - // If the tree has 2 children - if (node->get_right_child()) - n_children = 2; - // Else if only a left child - else if (node->get_left_child()) - n_children = 1; - // Else no child + + // If the node has 2 children + if (node->get_right_child()) + n_children = 2; + // Else if only a left child + else if (node->get_left_child()) + n_children = 1; + // Else no child else - n_children = 0; + n_children = 0; // If the node is in the interval if(node->get_element()->get_time() <= I->_right && @@ -113,12 +154,12 @@ void DrawTree<D, E>::browse_tree(Interval * I, Node<E> * node) { if (I->_right - I->_left > _min_size) { // Launching in both children if (n_children >= 1) - browse_tree(new Interval(I->_left, node->get_element()->get_time()), - node->get_left_child()); + browse_tree(new Interval(I->_left, node->get_element()->get_time()), + node->get_left_child()); if (n_children >= 2) - browse_tree(new Interval(node->get_element()->get_time(), I->_right), - node->get_right_child()); - + browse_tree(new Interval(node->get_element()->get_time(), I->_right), + node->get_right_child()); + // If node's left son has a conflict on it's left side if(n_children >= 1 && node->get_left_child()->_left_interval) { // Setting the node's left interval as busy @@ -130,56 +171,65 @@ void DrawTree<D, E>::browse_tree(Interval * I, Node<E> * node) { node->_left_interval = NULL; } + // Looking for conflict to display the node if(n_children >= 2 && node->get_left_child()->_right_interval && - node->get_right_child()->_left_interval) { - // If node is too close of the problematic area by both sides - if(node->get_element()->get_time() - node->get_left_child()->_right_interval->_right < _min_size && - node->get_right_child()->_left_interval->_left - node->get_element()->get_time() < _min_size) { + node->get_right_child()->_left_interval) { + + // If node is too close of the problematic area by both sides + if(node->get_element()->get_time() - node->get_left_child()->_right_interval->_right < _min_size && + node->get_right_child()->_left_interval->_left - node->get_element()->get_time() < _min_size) { // Drawing a crowded area draw_busy(new Interval(node->get_left_child()->_right_interval->_left, - node->get_right_child()->_left_interval->_right)); + node->get_right_child()->_left_interval->_right)); displayed = true; - delete node->get_left_child()->_right_interval; - if (node->get_left_child()->_right_interval != node->get_right_child()->_left_interval) + /////////////////////ATTENTION SOLUTION TEMPORAIRE + if(!node->get_left_child()->_right_interval) + delete node->get_left_child()->_right_interval; + if (!node->get_left_child()->_left_interval && + node->get_left_child()->_right_interval != node->get_right_child()->_left_interval) delete node->get_right_child()->_left_interval; - node->get_right_child()->_left_interval = NULL; - node->get_left_child()->_right_interval = NULL; - } - } - // Else if problem possible with the left child : it's right interval - else if (n_children >= 1 && node->get_left_child()->_right_interval) { - // If node is in the problematic area - if(node->get_element()->get_time() - node->get_left_child()->_right_interval->_right < _min_size) { + node->get_right_child()->_left_interval = NULL; + node->get_left_child()->_right_interval = NULL; + } + } + // Else if problem possible with the left child : it's right interval + else if (n_children >= 1 && node->get_left_child()->_right_interval) { + // If node is in the problematic area + if(node->get_element()->get_time() - node->get_left_child()->_right_interval->_right < _min_size) { displayed = true; - draw_busy(new Interval(node->get_left_child()->_right_interval->_left, - node->get_element()->get_time())); - delete node->get_left_child()->_right_interval; - node->get_left_child()->_right_interval = NULL; - } - else { - draw_busy(node->get_left_child()->_right_interval); - } - } + draw_busy(new Interval(node->get_left_child()->_right_interval->_left, + node->get_element()->get_time())); + /////////////////////ATTENTION SOLUTION TEMPORAIRE + if(!node->get_left_child()->_right_interval) + delete node->get_left_child()->_right_interval; + node->get_left_child()->_right_interval = NULL; + } + else { + draw_busy(node->get_left_child()->_right_interval); + } + } // Else if problem possible with the right child : it's left interval else if (n_children >= 2 && node->get_right_child()->_left_interval) { if(node->get_right_child()->_left_interval->_left - node->get_element()->get_time() < _min_size) { displayed = true; - draw_busy(new Interval(node->get_element()->get_time(), - node->get_right_child()->_left_interval->_right)); - delete node->get_right_child()->_left_interval; - node->get_right_child()->_left_interval = NULL; + draw_busy(new Interval(node->get_element()->get_time(), + node->get_right_child()->_left_interval->_right)); + /////////////////////ATTENTION SOLUTION TEMPORAIRE + if(!node->get_right_child()->_left_interval) + delete node->get_right_child()->_left_interval; + node->get_right_child()->_left_interval = NULL; } else { draw_busy(node->get_right_child()->_left_interval); - } - } - - + } + } + + // If node's right son has a conflict on it's right side if(n_children >= 2 && node->get_right_child()->_right_interval) { // Setting the node's right interval as busy - node->_right_interval = node->get_right_child()->_right_interval; + node->_right_interval = node->get_right_child()->_right_interval; } // Else no problem on the right else { @@ -187,29 +237,29 @@ void DrawTree<D, E>::browse_tree(Interval * I, Node<E> * node) { } - // Making sur node has been displayed + // Making sure node has been displayed if(!displayed) { DrawNode<D, E>::draw_node(this, node); } } // end if has enough space else { - // Cannot display node so his both busy interval are the same and value I + // Cannot display node so the busy intervals are the same and value I node->_left_interval = I; - node->_right_interval = I; + node->_right_interval = I; } } //end if is in the interval else { // If node is after the interval - if(n_children >= 1 && node->get_element()->get_time()>I->_right) { + if (n_children >= 1 && node->get_element()->get_time() > I->_right) { browse_tree(I, node->get_left_child()); - node->_left_interval = node->get_left_child()->_left_interval; - node->_right_interval = NULL; + node->_left_interval = node->get_left_child()->_left_interval; + node->_right_interval = NULL; } // Else he is before else if (n_children >= 2) { - browse_tree(I, node->get_right_child()); - node->_left_interval = NULL; - node->_right_interval = node->get_right_child()->_right_interval; + browse_tree(I, node->get_right_child()); + node->_left_interval = NULL; + node->_right_interval = node->get_right_child()->_right_interval; } } // end else is in the interval } diff --git a/src/trace/State.cpp b/src/trace/State.cpp index 7408bcac79df719ff9eed476dba1aee64de68fce..59ce35e7ce826333d50af16339255765cd240ed4 100644 --- a/src/trace/State.cpp +++ b/src/trace/State.cpp @@ -25,3 +25,6 @@ const EntityValue *State::get_value() const { return _value; } +const Date State::get_time() const{ + return _start; +} diff --git a/src/trace/State.hpp b/src/trace/State.hpp index 064ee00f72d4aeb7baed60369702cd15db062d16..d0733a17ec0011c8ed3814bdb1432f06f6fd2a8a 100644 --- a/src/trace/State.hpp +++ b/src/trace/State.hpp @@ -59,6 +59,12 @@ public: * \return Pointer to the Entityvalue or NULL if it has no value */ const EntityValue *get_value() const; + + /*! + * \fn get_time() + * \brief Get the time of the state + */ + const Date get_time() const; }; #endif diff --git a/src/trace/tree/BinaryTree.hpp b/src/trace/tree/BinaryTree.hpp index 16e3bfabdbe4be871eb2d915018606730c005ba1..55b5baa2c43c7347a31e5d0a70e2034fcc0bc968 100644 --- a/src/trace/tree/BinaryTree.hpp +++ b/src/trace/tree/BinaryTree.hpp @@ -36,7 +36,7 @@ public: // Calculate n and m as size = 2^n - 1 + m and m < 2^n int n = 0; - int a = 1; + unsigned int a = 1; while (size >= 2*a - 1) { a *= 2; n++;