2 #include "view_btree.h"
3 #include "view_btree_data.h"
4 #include <sigc++/slot.h>
6 double ViewBTree::byte_to_pixels = 0;
7 double ViewBTree::node_width = 0;
9 ViewBTree::ViewBTree (Canvas::Group *parent, std::string filename, uint block_size):Canvas::Group (*parent, 0, 0),
10 BTree (filename, block_size)
12 /* Cada bytes lo hago de 5 units de ancho */
13 node_width = 3 * block_size; // 64 == blocksize
14 byte_to_pixels = node_width/block_size; // TODO : 64 == BlockSize
19 void ViewBTree::AddNode (uint num)
21 if (node_placed[num]) {
22 std::cout << "WARNING : Tratando de agregar de nuevo el nodo " << num << std::endl;
26 node_placed[num] = true;
29 uchar *node = ReadBlock (num);
31 BTreeNodeHeader node_h;
32 ReadNodoHeader (node, &node_h);
35 max_level = node_h.level;
37 y = (max_level - node_h.level)*(NODE_HEIGHT+10);
40 std::list<BTreeData *> keys = ReadKeys (node, node_h);
42 ViewNode *vnode = new ViewNode (this, num, node_h, keys);
43 vnode->property_y () = y;
44 vnode->property_x () = pos_x[node_h.level];
45 pos_x[node_h.level] += ViewBTree::node_width+10;
46 vnode->signal_selected().connect ( sigc::mem_fun (*this, &ViewBTree::on_item_selected) );
48 std::list<uint> childs = vnode->getChilds ();
49 std::list<uint>::iterator hit = childs.begin ();
50 while (hit != childs.end ()) {
52 std::cout << "WARNING : Referencia a 0 encontrada!!" << std::endl;
61 void ViewBTree::on_item_selected (BTreeData *data, uint num, ViewNode *vnode)
63 BTreeNodeHeader node_h;
66 node = ReadBlock (num);
67 ReadNodoHeader (node, &node_h);
71 if (vnode != last_selected)
72 last_selected->SetSelected (false);
73 last_selected = vnode;
74 vnode->SetSelected (true);
75 m_signal_selected (data, node_h);
78 ViewBTree::type_signal_selected ViewBTree::signal_selected ()
80 return m_signal_selected;