2 #include "view_btree.h"
3 #include "view_btree_data.h"
5 double ViewBTree::byte_to_pixels = 0;
7 ViewBTree::ViewBTree (Canvas::Group *parent, std::string filename):Canvas::Group (*parent, 0, 0),
10 /* TODO : hace que el arbol se abra de un archivo ya creado o que se
13 for (int i=0; i<=64; i++) {
19 byte_to_pixels = NODE_WIDTH/64; // TODO : 64 == BlockSize
24 void ViewBTree::AddNode (uint num)
26 if (node_placed[num]) {
27 std::cout << "WARNING : Tratando de agregar de nuevo el nodo " << num << std::endl;
31 node_placed[num] = true;
34 uchar *node = ReadBlock (num);
36 BTreeNodeHeader node_h;
37 ReadNodoHeader (node, &node_h);
40 max_level = node_h.level;
42 y = (max_level - node_h.level)*(NODE_HEIGHT+10);
45 std::list<BTreeData *> keys = ReadKeys (node, node_h);
47 ViewNode *vnode = new ViewNode (this, num, node_h, keys);
48 vnode->property_y () = y;
49 vnode->property_x () = pos_x[node_h.level];
50 pos_x[node_h.level] += NODE_WIDTH+10;
52 std::list<uint> childs = vnode->getChilds ();
53 std::list<uint>::iterator hit = childs.begin ();
54 while (hit != childs.end ()) {
56 std::cout << "WARNING : Referencia a 0 encontrada!!" << std::endl;
65 ViewNode::ViewNode (Canvas::Group *parent, uint num, BTreeNodeHeader &header, std::list<BTreeData *> &keys)
66 : Canvas::Group (*parent)
68 double header_w = ViewBTree::byte_to_pixels * sizeof (BTreeNodeHeader);
71 Canvas::Rect *fondo = new Canvas::Rect (*this, 0, 0, NODE_WIDTH, NODE_HEIGHT);
72 fondo->property_fill_color() = "gray";
73 fondo->property_outline_color() = "black";
76 Canvas::Rect *h = new Canvas::Rect (*this, 0, 0, header_w, NODE_HEIGHT);
77 h->property_fill_color() = "blue";
78 h->property_outline_color() = "black";
85 new Canvas::Text (*this, header_w/2, NODE_HEIGHT/2, node_num);
89 std::list<BTreeData *>::iterator it = keys.begin ();
90 while (it != keys.end ()) {
91 BTreeData *data = (*it);
92 double w = ViewBTree::byte_to_pixels * data->Size ();
94 ViewBTreeData *v = ViewBTreeData::Create (data, this, x, 0, w+x, NODE_HEIGHT);
99 if (!dynamic_cast<BTreeLeafData *>(data)) {
100 /* Si no es un dato de una hoja, tiene hijos */
101 hijos.push_back (data->getChild ());