From 7889c60992a11bbf4f8842a3ebdb8a8c909d260b Mon Sep 17 00:00:00 2001
From: Thibault Soucarre <thibault.soucarre@inria.fr>
Date: Fri, 20 Jun 2014 15:26:45 +0000
Subject: [PATCH] Changement algorithme browse_container

---
 src/trace/DrawTrace.hpp | 53 +++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/src/trace/DrawTrace.hpp b/src/trace/DrawTrace.hpp
index ee2bf127..f08dc109 100644
--- a/src/trace/DrawTrace.hpp
+++ b/src/trace/DrawTrace.hpp
@@ -48,6 +48,8 @@
 #ifndef DRAW_TRACE_HPP
 #define DRAW_TRACE_HPP
 
+#include <iostream>
+
 /*
  * Theses constants can not be put as static const float because it is a template and there binary representation is not normed by the C++ langage.
  */
@@ -270,7 +272,7 @@ public:
     template<class T>
     inline void browse_container_tree(T* draw_object, Trace* trace, std::vector<const Container *> *container){
         /*** Drawing containers ***/
-        int position = 0;
+        Element_pos y = 0.;
 
         const Container::Vector *root_containers = trace->get_view_root_containers();
         if (root_containers->empty())
@@ -285,7 +287,7 @@ public:
                  i++)
                 // Use the fact that if a container is selected, then it implies that all his ancestors are
                 if(is_in_set(*i,container))
-                    position += browse_container(draw_object, *i, position, 0,container);
+                    y += browse_container(draw_object, *i, 0., y, _container_width, 0., container);
         }
     }/* end browse_container_tree */
 
@@ -297,24 +299,27 @@ public:
      * current depth in the tree
      */
     template<class T>
-    int browse_container(T* draw_object, const Container *container, int position, int depth,
-                         std::vector<const Container *> *set_container) {
-        int size = 0;
+    Element_pos browse_container(T* draw_object, const Container *container, Element_pos x, Element_pos y,
+                         Element_pos w, Element_pos h, std::vector<const Container *> *set_container) {
+        //int size = 0;
 
         // Draw children:
         // we want to display only children meant to be displayed
         const Container::Vector *children = container->get_view_children();
         if( children->empty() )
             children = container->get_children();
-
+        /*if(!children.empty())
+         h = 0.;*/
         for (Container::VectorIt i = children->begin();
             i != children->end();
             i++) {
-            if(is_in_set(*i,set_container))
-                size += browse_container(draw_object, (*i), position+size, depth+1,set_container);
+            h += browse_container(draw_object, (*i), x + _container_width + _container_h_space, y + h, _container_width, 0., set_container) + _container_v_space;
         }
+        // h -= _container_v_space;
+        /*if(is_in_set(*i,set_container))
+         size += browse_container(draw_object, (*i), position+size, depth+1,set_container);*/
 
-        // Use one line for states and events
+            // Use one line for states and events
 #ifdef USE_ITC
         if ( (container->get_states() != NULL && !container->get_states()->empty()) ||
              (container->get_events() != NULL && !container->get_events()->empty()) )
@@ -323,31 +328,32 @@ public:
              !container->get_events()->empty() )
 #endif
         {
-            size++;
+            h += _container_height + _container_v_space;
             _entity_containers.push_back(container);
         }
 
         // Store the position to draw links
-        _container_positions[container] = position; // First line after children
-        _container_sizes[container]     = size; // First line after children
+        _container_positions[container] = y/(_container_height + _container_v_space) /*+ 7 * _container_v_space*/;//position; // First line after children
+        _container_sizes[container] = h/(_container_height + _container_v_space);//size; // First line after children
 
         // Use one line for each variable
         if (container->get_variable_number() > 0) {
             _variable_containers.push_back(container);
-            size += container->get_variable_number();
+            h += (_container_height + _container_v_space) * container->get_variable_number();
         }
+        h -= _container_v_space;
 
-        if (size < 1) // Minimum size
-            size = 1;
+        if (h < _container_height) // Minimum size
+            h = _container_height;
 
         // Push containers with links to draw
         if (!container->get_links()->empty())
             _link_containers.push_back(container);
 
         // Draw this container
-        draw_container(draw_object, position, size, depth, container->get_name().to_string());
+        draw_container(draw_object, x, y, w, h, container->get_name().to_string());
 
-        return size;
+        return h;
     }
 
     /*!
@@ -359,12 +365,12 @@ public:
      * \param text Name of the container
      */
     template<class T>
-    inline void draw_container(T* draw_object, int position, int size, int depth, const std::string &text) {
-        Element_pos x      = depth   *(_container_width +_container_h_space) + _container_h_space/2;
-        Element_pos y      = position*(_container_height+_container_v_space) + _container_v_space/2;
-        Element_pos height = size    *(_container_height+_container_v_space) - _container_v_space;
-        draw_object->draw_container(x, y, _container_width, height);
-        draw_object->draw_container_text(x, y+height/2, text);
+    inline void draw_container(T* draw_object, Element_pos x, Element_pos y, Element_pos w, Element_pos h, const std::string &text) {
+        //Element_pos x      = depth   *(_container_width +_container_h_space) + _container_h_space/2;
+        //Element_pos y      = position*(_container_height+_container_v_space) + _container_v_space/2;
+        //Element_pos height = size    *(_container_height+_container_v_space) - _container_v_space;
+        draw_object->draw_container(x, y+_container_v_space/2, w, h);
+        draw_object->draw_container_text(x, y+h/2, text);
     }
 
     /*!
@@ -373,6 +379,7 @@ public:
     template<class T>
     inline void browse_entities(T* draw_object, double zoom, Interval* interval, std::vector<const Container *> *set_container) {
         //////////////////////////////////////////////////////////
+        std::cout << "browse entities" << std::endl;
         const Container *container;
         StateChange::Tree *state_tree;
         Event::Tree *event_tree;
-- 
GitLab