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 @@
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
}
......@@ -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
......
......@@ -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,10 +231,16 @@ public:
container = *c;
position = _container_positions[container];
state_list = container->get_states();
state_tree = container->get_states();
event_tree = container->get_events();
if (!state_list->empty() || !event_tree->empty()) {
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++) {
......@@ -249,13 +253,13 @@ public:
!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;
/* 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);
/* 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 */
......@@ -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
......
......@@ -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,11 +95,49 @@ 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 the node has 2 children
if (node->get_right_child())
n_children = 2;
// Else if only a left child
......@@ -130,9 +171,11 @@ 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) {
......@@ -140,8 +183,11 @@ void DrawTree<D, E>::browse_tree(Interval * I, Node<E> * node) {
draw_busy(new Interval(node->get_left_child()->_right_interval->_left,
node->get_right_child()->_left_interval->_right));
displayed = true;
/////////////////////ATTENTION SOLUTION TEMPORAIRE
if(!node->get_left_child()->_right_interval)
delete node->get_left_child()->_right_interval;
if (node->get_left_child()->_right_interval != node->get_right_child()->_left_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;
......@@ -154,6 +200,8 @@ void DrawTree<D, E>::browse_tree(Interval * I, Node<E> * node) {
displayed = true;
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;
}
......@@ -167,6 +215,8 @@ void DrawTree<D, E>::browse_tree(Interval * I, Node<E> * node) {
displayed = true;
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;
}
......@@ -187,20 +237,20 @@ 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;
}
} //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;
......
......@@ -25,3 +25,6 @@ const EntityValue *State::get_value() const {
return _value;
}
const Date State::get_time() const{
return _start;
}
......@@ -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
......@@ -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++;
......
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